Unable to achieve Parallel Run on Multiple threads of same Browser inTestNG

Hi All, Need an urgent help Trying to give all required info below. Thanks in Advance!

We have Selenium>TestNG Maven project where Parallel Execution to be implemented using TestNG suite for Multiple threads of same Browser(preferably Chrome).

Our Test Cases are defined on Class level i.e. each class  is a test case with 4 methods in it- having

  1. @BeforeClass
  2. @Test
  3. @AfterClass and
  4. DataProvider.

Now I have to Run all the Classes using testNG suite xml: Which I have setup Like below-

<suite name = “Regression Test Suite for SG” verbose=”2″ thread-count= “4” data-provider-thread-count=”4″ parallel= “instances” preserve-order=”true” >

<parameter name=”URL” value=”https://sit04grid.abc.com.hk/index.aspx” />

<parameter name=”countryCode” value=”SG” />

<parameter name=”driver” value=”ChromeDriver” />

<parameter name=”timeout” value=”6″ />

<parameter name=”screenshotsLocation” value=”C:/TestAutomation/AutomationCode/HK/Screenshots/” />

<parameter name=”testDataXlFileName” value=”GRID_SG_TESTDATA.xls” />

<parameter name=”testDataSheetName” value=”GRID_SG_TESTDATA” />

<!– Below test data parameters related to  each TestCase as we have around 30 classes i.e. TestCases –>

<parameter name=”testDataStartPoint1″ value=”TC001_START” />

<parameter name=”testDataEndPoint1″ value=”TC001_END” />

<parameter name=”testDescription1″ value=”Verify Create New Account and Contact” />

<test name=”Regression tests for SG” >

<classes>

<class name=”com.abc.testClasses.TC001_VerifyCreateNewAccountContact”/>

<class name=”com.abc.testClasses.TC002_VerifyCreateNewProperty”/>

<class name=”com.cbreGRID.testClasses.TC003_VerifyUpdateProperty_Info” />

<class name=”com.cbreGRID.testClasses.TC004_VerifyUpdateProperty_AC_Info

<!– …. …..and So on for all 30 test cases until TC030 ….********* –>

</classes>

</test>

</suite>

 

TestCase Level Scripts High Level design:

 

//**************** @Test annotation*************************

public class TC001_VerifyCreateNewAccountContact extends TestConfiguration {

@Test(enabled = true, groups = { “FunctionalTest” }, dataProvider = dataProviderName)

public void tc001_VerifyCreateNewAccountAndContact(String actName, String phone, String accountBillingCountry,String accountBillingStateProvince, String accountBillingCity) throws Exception {

 

// creating page objects involved in this test using Page classes defined in Framework

 

HomePage hmePage = (HomePage) sessions.get(“HomePage”);

AccountsContactSearchPage accountsContactSearchPage = (AccountsContactSearchPage) sessions.get(“AccountsContactSearchPage”);

Status tstStatus = new Status();

ApplicationReusableMethodsCollection objReusableMethods = new ApplicationReusableMethodsCollection();

GeneralUtilities genUtils = new GeneralUtilities();

 

/*Test starts here————————>*/

 

Doing xyz..Blah..Blah ..

}

}

 

//**************** @BeforeClass annotation *************************

@BeforeClass(enabled = true, groups = { “FunctionalTest” })

@Parameters({ “driver”, “timeout”, “URL”, “countryCode”, “screenshotsLocation”, “testDataXlFileName”, “testDataSheetName”,

“testDataStartPoint1”, “testDataEndPoint1”, “testDescription1” })

public void beforeClass(String driver, int timeout, String URL, String countryCde, String screenshotLocation,

String testDataXlFileName, String testDataSheetName, String testDataStartCell, String testDataEndCell) {

 

setUpBeforeClassConfiguration(driver, timeout, URL, countryCde,screenshotLocation, testDataXlFileName, testDataSheetName,

testDataStartCell, testDataEndCell, testDesc);

try {

HomePage hmePage = new HomePage(webDriver, timeOut);

sessions.put(“HomePage”, hmePage);

AccountsContactSearchPage accountsContactSearchPage = new AccountsContactSearchPage(webDriver, timeOut);

sessions.put(“AccountsContactSearchPage”, accountsContactSearchPage);

} catch (WebDriverException e) {

webDriver.quit();

}

 

}

 

//*********************  @After Class  ****************

 

@AfterClass(enabled = true, groups = { “FunctionalTest” }, alwaysRun = true)

public void afterClass() {

// shut down the browser

logger.info(“Close the Browser”);

webDriver.quit();

}

 

//**************** Data Provider ******************

 

@DataProvider(name = dataProviderName, parallel = true)

public Object[][] dataProvider() throws Exception {

Object[][] retObjArr = testData.getTestData(testDataXLFile, testDataSheet, testDataStartPoint,testDataEndPoint);

return (retObjArr);

 

//Here  getTestData is a method to read data from Excl which return the arrayTestData

 

}

for instantiating Browser we are using Browser store class  switch Switch statement in enum as below-

public BrowserStore(String browser_type) {
Properties prop = new Properties();
logger = Logger.getLogger(this.getClass().getName());

try {
// load a properties file
prop.load(BrowserStore.class.getClassLoader().getResourceAsStream(“Browser.properties”));

// get chrome driver location
chrome_driver_path = prop.getProperty(“chrome_driver_path”);
downloadPath = prop.getProperty(“chrome_driver_downloadPath”);

} catch (IOException e) {
logger.error(“Could not find property file”);
logger.error(e.getMessage());
}

// instantiating enum
Browser_type browser = Browser_type.valueOf(browser_type);
// switch statement to select the browser

try {
switch (browser) {
case ChromeDriver:
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put(“download.default_directory”, downloadPath);
ChromeOptions chromeOptions = new ChromeOptions();
chromeOptions.setting some option
System.setProperty(“webdriver.chrome.driver”, chrome_driver_path);
webDriver = new ChromeDriver(chromeOptions);
break;
case FirefoxDriver: //and so on..for other browsers.
}

} catch (Exception e) {
logger.info(“There is an exception in Browser Store”);
logger.info(e.getMessage());
// webDriver.quit();
e.printStackTrace();
}
}

//***************************************** out put  ******************

When running suite xml: I can see selenium openes up 4 threads of chrome browser but quits them all in a second only(one) last test seems to be executed fine but thats not Parallel run…

I see all 3 testfailed with DataProvider MisMatch error.

also weird thisng I see only TC003 is being run by all 4 threads.. as given below-

[TestRunner] Starting executor for test Regression tests for SG with time out:2147483647 milliseconds.
2018-02-16 01:09:04 INFO TC003_VerifyUpdateProperty_Gen_PropMgmt_Elvtr_Prkng_Info:69 – selecting browser driver : ChromeDriver
2018-02-16 01:09:04 INFO TC003_VerifyUpdateProperty_Gen_PropMgmt_Elvtr_Prkng_Info:69 – selecting browser driver : ChromeDriver
2018-02-16 01:09:04 INFO TC003_VerifyUpdateProperty_Gen_PropMgmt_Elvtr_Prkng_Info:71 – – is being executed via Thread Id: 10
2018-02-16 01:09:04 INFO TC003_VerifyUpdateProperty_Gen_PropMgmt_Elvtr_Prkng_Info:69 – selecting browser driver : ChromeDriver
2018-02-16 01:09:04 INFO TC003_VerifyUpdateProperty_Gen_PropMgmt_Elvtr_Prkng_Info:71 – – is being executed via Thread Id: 12
2018-02-16 01:09:04 INFO TC003_VerifyUpdateProperty_Gen_PropMgmt_Elvtr_Prkng_Info:71 – – is being executed via Thread Id: 11
2018-02-16 01:09:04 INFO TC003_VerifyUpdateProperty_Gen_PropMgmt_Elvtr_Prkng_Info:69 – selecting browser driver : ChromeDriver
2018-02-16 01:09:04 INFO TC003_VerifyUpdateProperty_Gen_PropMgmt_Elvtr_Prkng_Info:71 – – is being executed via Thread Id: 13
Starting ChromeDriver 2.34.522940 (1a76f96f66e3ca7b8e57d503b4dd3bccfba87af1) on port 43758
Only local connections are allowed.
Starting ChromeDriver 2.34.522940 (1a76f96f66e3ca7b8e57d503b4dd3bccfba87af1) on port 16560
Only local connections are allowed.
Starting ChromeDriver 2.34.522940 (1a76f96f66e3ca7b8e57d503b4dd3bccfba87af1) on port 26674
Only local connections are allowed.
Starting ChromeDriver 2.34.522940 (1a76f96f66e3ca7b8e57d503b4dd3bccfba87af1) on port 24860
Only local connections are allowed.
Feb 16, 2018 1:09:08 AM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: OSS

Default Asked on February 16, 2018 in Selenium WebDriver.
Add Comment
  • 0 Answer(s)
  • Your Answer

    By posting your answer, you agree to the privacy policy and terms of service.