Ragnarsson
Ragnarsson

Reputation: 1825

Running Tests parallel with TestNG doesn't work as expected

For some reason, I need to execute my tests parallel on IE11 and Chrome, each browser on separated Node machine. This is my testng.xml:

<suite name="Parallel" parallel="tests">    
    <test name="Performance Test Chrome">
        <parameter name="browser" value="Chrome"/>            
        <parameter name="remoteURL" value="http://myIP1:5555/wd/hub"/>
        <parameter name="user" value="user1"/>
        <classes>
            <class name="com.TestClass"/>
        </classes>
    </test>
    <test name="Performance Test IE11">
        <parameter name="browser" value="IE" />            
        <parameter name="remoteURL" value="http://myIP2:5555/wd/hub"/>
        <parameter name="user" value="user2"/>
        <classes>
            <class name="com.TestClass" />
        </classes>
    </test>
</suite>

This is my test method:

@Parameters({"browser", "remoteURL", "user"})
@Test
public void parallelTest(String browser, String remoteURL, String user) {
    // test steps
}

Expect: The test should open each browser on respectively Node machines at the same time and perform test steps (login with respectively user and do things ...). They are different users on different nodes to avoid sessions.

Actual: Browsers are actually opened at the same time on 2 nodes, but the test steps don't run through, they get stuck with NoSuchElementException, from login page on Chrome, and it goes a litte further with IE, but still the same problem

Note that if I run tests normal (by settings parallel="none"), then each test tag is executed successfully. I execute test within IntelliJ, by right click on testng.xml and run.

Am I missing some settings? Any help much appreciated. Thanks

Upvotes: 0

Views: 2494

Answers (1)

RocketRaccoon
RocketRaccoon

Reputation: 2599

When you want to run your tests in parallel you have to be sure that you resources, like browsers instances will be provided for each test execution. TestNG does not provide such flexibility in manging test instances on the fly like JUnit5 for example.

So for each test run you need new browser (usually). If you create your webdriver instance as static variable or singleton it won't be shared between parallel runs. It could be handled by making your drivers ThreadLocal.

Upvotes: 1

Related Questions