0
votes

I have a simple maven project with three class files. When I run my testng.xml file, tests are running in series.

I tried keeping parallel="classes", parallel="methods", parallel="tests" but no luck. Also tried by changing testng version from 6.9.0 to 7.0.0 but it didn't work.

Expectation:

Tests should run in parallel

What is happening:

Tests run in sequence

Below is my project and all files:

Test Class: 1

public class TestOne {

private static WebDriver driver;
private static String baseURL;

@Test
public void launch() throws IOException {
    baseURL = "http://www.gmail.com";
    System.setProperty("webdriver.chrome.driver", "path");
    WebDriver driver = new ChromeDriver();
    driver.get(baseURL);
    driver.quit();
    }
}

Test Class: 2

public class TestTwo {

private static WebDriver driver;
private static String baseURL;

@Test
public void launch() throws IOException {
    baseURL = "http://www.gmail.com";
    System.setProperty("webdriver.chrome.driver", "path");
    WebDriver driver = new ChromeDriver();
    driver.get(baseURL);
    driver.quit();
    }
}

Test Class: 3

public class TestThree {

private static WebDriver driver;
private static String baseURL;

@Test
public void launch() throws IOException {
    baseURL = "http://www.gmail.com";
    System.setProperty("webdriver.chrome.driver", "path");
    WebDriver driver = new ChromeDriver();
    driver.get(baseURL);
    driver.quit();
    }
}

TestNG xml:

!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd"

suite name="Test" parallel="tests" thread-count="3" data-provider-thread-count="5"

<test name="Launch">
    <classes>
        <class name="test.demo.grid.TestOne" />
        <class name="test.demo.grid.TestTwo" />
        <class name="test.demo.grid.TestThree" />
    </classes>
</test>

Version:

selenium-java = 3.4.0

testng = 6.14.3

=================================

Please let me know how I can fix it.

Thank you!

5
I am not sure but I think you need a parent <tests> .. .</tests> to cover all your test tags. This could be the reason. - pdrersin

5 Answers

0
votes

Try first a simple example logging the thread id on each test method, without calling ChromeDriver yet

long id = Thread.currentThread().getId();
    System.out.println("Sample test-method " + testName
            + ". Thread id is: " + id);

https://howtodoinjava.com/testng/testng-executing-parallel-tests/

If it logged the ids in parallel maybe is something related to ChromeDriver

0
votes

<test> tag is only one in your testng.xml and that is the reason, parallel execution is not working.

In your case, you need to use parallel="classes" and all the classes would execute parallely.

Edit:
You can use the testng.xml as:

<test name="Launch">
    <classes>
        <class name="test.demo.grid.TestOne" />
    </classes>
</test>
<test name="Second test">
    <classes>
        <class name="test.demo.grid.TestTwo" />
    </classes>
</test>
<test name="Third test">
    <classes>
        <class name="test.demo.grid.TestThree" />
    </classes>
</test>

And now use parallel="tests" in the testng.xml

0
votes

Try with parallel="classes" and without the data-provider-thread-count="5" because you are not using data provider here.

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Test" parallel="classes" thread-count="3">
<test name="Launch">
    <classes>
        <class name="test.demo.grid.TestOne" />
        <class name="test.demo.grid.TestTwo" />
        <class name="test.demo.grid.TestThree" />
    </classes>
</test>
</suite>
0
votes

You can try:

      <?xml version="1.0" encoding="UTF-8"?>
        <!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">

        <suite name="Suite" configfailurepolicy="continue">

        <parameter name="parallelSetup" value="tests" />
        <parameter name="threadsNumber" value="3" />


  <test name="Launch">
    <classes>
        <class name="test.demo.grid.TestOne" />
        <class name="test.demo.grid.TestTwo" />
        <class name="test.demo.grid.TestThree" />
    </classes>
</test>

        </suite> 
0
votes

add @BeforeClass annotation in every class and initialize WebDriver in that annotaion and close driver in @AfterClass annotion for every class