3

Hi i have designed a selenium test to run in parallel (25)

@Test(dataProvider = "getData" )
public void multiUserTest(String url, String username, String password)
        throws InterruptedException, IOException, FindFailed {

    DesiredCapabilities capabilities = DesiredCapabilities.chrome();
    capabilities.setBrowserName(prop.getProperty("browserName"));
    capabilities.setPlatform(Platform.WINDOWS);
    RemoteWebDriver driver = new RemoteWebDriver(new URL(prop.getProperty("url")), capabilities);

    WebDriverWait wait = new WebDriverWait(driver, 720); // 12 minutes wait.
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(50, TimeUnit.SECONDS);

    try {
        driver.get(url);
        driver.findElement(By.xpath(prop.getProperty("username"))).sendKeys(username);
        driver.findElement(By.xpath(prop.getProperty("password"))).sendKeys(password);
        driver.findElement(By.xpath(prop.getProperty("signin"))).click();
        }catch (Exception e) {
        e.printStackTrace();
    }

My data provider

@DataProvider(parallel = true)
public Object[][] getData() {

    Object data[][] = new Object[25][3];
    // row 1
    data[0][0] = "http:XXXX/login.html";
    data[0][1] = "XXX1@gmail.com";
    data[0][2] = "XX@123";

    // row 2
    data[1][0] = "http:XXXX/login.html";
    data[1][1] = "XXX2@gmail.com";
    data[1][2] = "XX@123";
    ..........


    // row 25
    data[24][0] = "http:XXXX/login.html";
    data[24][1] = "XXX25@gmail.com";
    data[24][2] = "XX@123";

and my xml file is

    <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Suite" parallel="methods"  thread-count="1" data-provider-thread-count="25">
  <test name="Test">
    <classes>
      <class name="XXX.MultiUserGuiTest"/>
    </classes>
  </test> <!-- Test -->
</suite> <!-- Suite -->

Now when i run my above test its running 10 tests at one go and after 10th test has finished then next 10 starts execution which is followed by 5 but i want to run my test where 25 should start execution at once

Just for reference i am adding a screenshot of my ec2 instances. There are 25 chrome, up and running also please have a look at mouse hover above chrome browserenter image description here

bot13
  • 99
  • 1
  • 15
Rajnish Kumar
  • 2,828
  • 5
  • 25
  • 39
  • where are you running your tests locally or on a grid? – Paras Jan 03 '17 at 09:01
  • on a grid .we have purchases amazon EC2 instance for our test – Rajnish Kumar Jan 03 '17 at 09:14
  • can you check how many nodes are setup on the grid machine and their max instances? – Paras Jan 03 '17 at 09:14
  • yes there are 25 nodes up – Rajnish Kumar Jan 03 '17 at 09:15
  • try the code in the local machine once. It worked for me. Double check how you are running the tests? using XML? then check `data-provider-thread-count="25"`is really set in the machine. What you mentioned is the default behaviour (default value = 10) – Naveen Kumar R B Jan 03 '17 at 09:19
  • and as per documentation of TestNG Parallel data providers running from an XML file share the same pool of threads, which has a size of 10 by default. You can modify this value in the tag of your XML file: ... If you want to run a few specific data providers in a different thread pool, you need to run them from a different XML file. – Rajnish Kumar Jan 03 '17 at 09:20
  • @ naveen you are saying in local machine at your end above setup opened 25 parallel test at once – Rajnish Kumar Jan 03 '17 at 09:22
  • configuration seems fine to me.. it should open 25 threads parallely. – Paras Jan 03 '17 at 09:23
  • Yeah, I tried without the concept of Selenium. just printing the values in test method and nothing else. I can all ran in 25 threads. – Naveen Kumar R B Jan 03 '17 at 09:24
  • try removing `thread-count="1"` from `suite` tag. – Paras Jan 03 '17 at 09:28
  • @ paras i have tried running thread-count="1" or thread-count="25" or complete removing thread-count but all time same result – Rajnish Kumar Jan 03 '17 at 09:29
  • I tried with creating `ChromeDriver` instances in the test code. all 25 chrome browsers launched parallely (thought it is too slow). so, the problem seems to be in RemoteWebDriver. Need more exploration on this. – Naveen Kumar R B Jan 03 '17 at 09:37
  • Are you using `hub-node` concept of the grid? because I don't see you using the hub URL (same for all 25 nodes). If you are using `hub-node` concept and all nodes are registered to hub, confirm with Hub console. And also make sure all the nodes satisfy the requirements (Windows platform and given browser) in order to be picked by Hub to run the test. – Naveen Kumar R B Jan 03 '17 at 09:57
  • @ Naveen thi si my hub url and i have kept this inside a properties file http://jNghC1DwVLrdV:Y1Pf7iC4oZTRZUsN@60CQUPO4.gridlastic.com:80/wd/hub and also i have attached a screenshot of the hub please refer that – Rajnish Kumar Jan 03 '17 at 10:03
  • I can see all the nodes (except 2) having Firefox browser, but not Chrome. In All 25 nodes, are you launching chrome browser? in that case, as only one machine/node is available with the given combination. – Naveen Kumar R B Jan 03 '17 at 10:31
  • @rajNishKuMar - Can you please share the contents of http://localhost:4444/grid/console?config=true&configDebug=true (no screenshots please) preferably as an offline html file ? I think this has something to do with your Grid configuration ( I guess you are using a grid from gridlastic and am not sure if they would expose the grid configs). Feel free to scrub out sensitive data such as IP etc., [ Also please share the node configuration section from this same page as well. One node info is enough, if all your nodes have the same config ] – Krishnan Mahadevan Jan 04 '17 at 02:48

2 Answers2

3

To resolve the trouble:

@BeforeClass
    public void setupClassName(ITestContext context) {
        context.getCurrentXmlTest().getSuite().setDataProviderThreadCount(100);
        context.getCurrentXmlTest().getSuite().setPreserveOrder(false);
    }
Andrey
  • 53
  • 1
  • 2
  • 11
2

Hi we have figured out a way through which we were able to run our 25 test in parallel ** But i don't think this is a standard way of doing this **. Please provide your feedback or a better way of doing above scenario.

Solution Instead of using data form data provider we have removed data provider completely and instead we are calling parameters form testng.xml file as Parameters by using

  @Parameters({"param 1","param 2","param 3","and so on"}) in our test

and now i can see my 25 nodes active at same time and perform all actions successfully.

Rajnish Kumar
  • 2,828
  • 5
  • 25
  • 39