3

I am using the below TestNG Config to enable parallel execution of Selenium tests.

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

<suite name="Test-Automation" parallel="methods" thread-count="2" verbose="1">

    <test name="Suite Test">
        <classes>
            <class name="SampleTest">
                <methods>
                    <include name="firstTest"/>
                    <include name="secondTest"/>
                    <include name="thirdTest"/>
                </methods>
            </class>
        </classes>
    </test>
</suite>

Java Code:

@Test(dataProvider = "TestData")
public void firstTest(String data){
   //Code
}

@Test(dataProvider = "TestData")
public void secondTest(String data){
   //Code
}

@Test(dataProvider = "TestData")
public void thirdTest(String data){
   //Code
}

The Selenium tests are expected to run in parallel. I expect 2 browsers to be open and run the test script.

But I see only 1 browser and all 3 tests run one after the other and not in parallel. I have tried using test, methods, class, instance options for "parallel" attribute.

Any help?

2
  • What version of TestNG are you working with ? Commented Jan 22, 2018 at 14:13
  • @KrishnanMahadevan : I am using 6.13.1 Commented Jan 22, 2018 at 14:31

2 Answers 2

6

This is due to a bug in TestNG 6.13.1 [ See GITHUB-1636 for more details ]

I have fixed this in the latest SNAPSHOT of TestNG (6.14-SNAPSHOT) and this should be available for use in the released version of TestNG (6.14).

But until then, please alter your suite xml file to look like below :

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

<suite name="Test-Automation" parallel="methods" thread-count="2" verbose="1">
    <test name="Suite Test" parallel="methods" thread-count="2" verbose="1">
        <classes>
            <class name="SampleTest">
                <methods>
                    <include name="firstTest"/>
                    <include name="secondTest"/>
                    <include name="thirdTest"/>
                </methods>
            </class>
        </classes>
    </test>
</suite>

The work-around is basically to add the attributes parallel="methods" thread-count="2" at the <test> level also.

Sign up to request clarification or add additional context in comments.

3 Comments

I am seeing this problem again in 6.14.3 github.com/cbeust/testng/issues/1898
@sjethvani - Then you should file a new bug, and include all supporting information along with samples etc., which can be used to recreate the problem.
I have already commented this thing under relevant issue (github.com/cbeust/testng/issues/1898) . Should I file a new issue ?
0

Seperate all the test and then try with parallel="test"

    <test name="Suite Test1">
        <classes>
              <class name="//..//packg name..SampleTest">

            </class>
        </classes>
    </test>
  <test name="Suite Test2">
        <classes>
            <class name="//..//SampleTest">

            </class>
        </classes>
    </test>
  <test name="Suite Test3">
        <classes>
            <class name="//..//packg name..SampleTest">

            </class>
        </classes>
    </test>

</suite>

3 Comments

Is separating all methods from 1 class to multiple test, the only way? All test methods are from single class.
This is incorrect. Separating a class with 3 methods that are part of a single <test> tag into 3 <test> tags with each class and one method is the same. This doesn't solve the problem.
ACtually this duplication works and runs in 2 browsers parallel. But this will make duplicated lines in xml config.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.