Help solicited with parallel testing in multiple browsers and dataprovider

57 views
Skip to first unread message

Anil V Cherian

unread,
Sep 27, 2015, 1:52:59 AM9/27/15
to Selenium Users
Hi All,

I am currently trying to build a webdriver suite using testNG. I am quite new to java and testNG.

Use Case:
Executing a test suite consisting of three testNG classes (each with a single test method and having dataprovider, loaded from DB run time) in parallel in multiple browsers.

So far I was able to run the suite sequentially. Hope that a thread per browser and dataprovider combination may be a solution here. But I am unable to implement it due to lack of knowledge.

When making the tests to run parallel in testNG xml suite, browsers open in parallel, but app URL is being opened only in one instance and data(user name) for all the instances are concatenated and send to the opened app user name field.

Design is in such a way that each test(1 method per test) case extends a base class to get its driver and dataprovider.

I tried to make driver thread safe looking at a nice blog created by Krishnan. But I was not really successful in implementing it for my case. Mainly I would like to have the browser available till end of the suite.

May I request your help for a solution?

Thanks and Kind Regards
Anil

Krishnan Mahadevan

unread,
Sep 27, 2015, 2:22:12 AM9/27/15
to Selenium Users
You would need to show us the code you have so far. That would be a good start.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

Anil

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/1bb95915-34f4-43b0-a661-ae12f8fe1823%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Anil V Cherian

unread,
Sep 27, 2015, 11:43:26 AM9/27/15
to Selenium Users
Hi Krishnan,
Thank you for replying to my post. I will share the code by tomorrow.

Thank you
Anil

Anil V Cherian

unread,
Sep 27, 2015, 11:29:29 PM9/27/15
to Selenium Users
Hi Krishnan,

Please find attached the files specified in the post. I am not able to attach all the files. Hence pasting the rest of the files below. Could you please have a look and share your feedback?

testNG.xml

<?xml version="1.0" encoding="UTF-8"?>
<suite name="CreateAccount" parallel="true" thread-count="5" data-provider-thread-count="5">
    
  <test name="Test IE">
    <parameter name="BrowserName" value="internetexplorer"></parameter> 
    <classes>
      <class name="LoginToApp"/>
      <class name="CreateUser"/>
      <class name="Logout"/>
    </classes>
  </test>
  
  
  <test name="Test Chrome" >
    <parameter name="BrowserName" value="chrome"></parameter> 
    <classes>
      <class name="LoginToApp"/>
      <class name="CreateUser"/>
      <class name="Logout"/>
    </classes>
  </test> 
  
  <test name="Test Firefox" >
    <parameter name="BrowserName" value="firefox"></parameter> 
    <classes>
      <class name="LoginToApp"/>
      <class name="CreateUser"/>
      <class name="Logout"/>
    </classes>
  </test> 
  
</suite> <!-- Suite -->


LocalDriverFactory 

public class LocalDriverFactory {
static WebDriver setDriver(String browserName){
DesiredCapabilities caps = null;
WebDriver bDriver = null;
File browserDriverServer;
switch (browserName.toLowerCase()) {
case "chrome":
//Setup for Grid capability
caps = DesiredCapabilities.chrome();
break;
case "firefox":
//Setup for Grid
caps = DesiredCapabilities.firefox();
break;
case "internetexplorer":
//setup for Grid
caps = DesiredCapabilities.internetExplorer();
default:
break;
}
bDriver = new RemoteWebDriver(caps);
return bDriver;
}
}

#############Tests####################
Login Test

public class LoginToApp extends Driver  {

  @BeforeTest
  public void getTestDataClass(){
 String sqlToExecute = "Select [User Name], [password] from Login;";
 setTestDataSql(sqlToExecute);
  }
  
  @Test(dataProvider = "DB Data")
  public void Login (String userName, String pwd) {
//code to Login
driver.get("http://www.google.com");
driver.findElement(By.name("q")).sendKeys(userName);
  }
}


Create User 

public class createUser extends Driver  {

  @BeforeTest
  public void getTestDataClass(){
 String sqlToExecute = "Select [First Name], [Last Name] from User;";
 setTestDataSql(sqlToExecute);
  }
  
  @Test(dataProvider = "DB Data")
  public void Login (String fName, String lName) {
//code to Login
System.out.println("Executing the work-flow to create new user");
driver.findElement(By.name(fNameUI)).sendKeys(fName);//fNameUI is the name attribute of the UI element
//further code for user Creation
  }
}


Logout
public class Logout extends Driver  {

    public void logout () {
//code to Logout
  }
}
driver.java
dbDriver.java

Anil V Cherian

unread,
Oct 1, 2015, 3:09:39 PM10/1/15
to Selenium Users
Hi All,

I tried making the driver thread local. But once the same test class is instantiated from tests per browser, the data being fetched by data provider from DB in two threads is sent to only one of the browser handler which already opened the URL.The second browser still waiting for commands.

I am really lost here. I tried to read a lot of blogs over internet and because of my limited exposure to TestNG framework and Java, I could not find out a solution. May I know what I am trying to do with data provider makes sense in testNG world?

Cheers
Anil

Krishnan mahadevan

unread,
Oct 2, 2015, 12:09:43 AM10/2/15
to seleniu...@googlegroups.com
Anil

Can you please show us the code that you have so far ?

-Krishnan Mahadevan


"All the desirable things in life are either illegal, expensive, fattening or in love with someone else"

From: Anil V Cherian
Sent: ‎02-‎10-‎2015 00:40
To: Selenium Users
Subject: Re: [selenium-users] Help solicited with parallel testing in multiplebrowsers and dataprovider

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.

Anil Varghese

unread,
Oct 2, 2015, 12:33:19 AM10/2/15
to seleniu...@googlegroups.com
Hi Krishnan,

I have already shared a prototype of the code in my post. Since the original code is  in my office laptop, I am unable to share it.

The idea is to have a modular approach and create a suite on the fly and run the same suite in parallel in different browsers.

Could you pls let me know if the code I shared is not accessible?

Cheers
Anil

From: Krishnan mahadevan
Sent: ‎02/‎10/‎2015 09:39
To: seleniu...@googlegroups.com
Subject: RE: [selenium-users] Help solicited with parallel testing inmultiplebrowsers and dataprovider

You received this message because you are subscribed to a topic in the Google Groups "Selenium Users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/selenium-users/pQEcfnYxyXM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to selenium-user...@googlegroups.com.

To post to this group, send email to seleniu...@googlegroups.com.

Anil V Cherian

unread,
Oct 2, 2015, 4:01:57 AM10/2/15
to Selenium Users
Hi All,

I was able to achieve the parallel execution of same test suite in multiple browsers using the isuite listners.

Thank you All for your help.

Cheers

Anil

Reply all
Reply to author
Forward
0 new messages