0
votes

Need a little help in getting the right approach to run the testng test cases in parallel.

Current setup. Running all the test cases using a single driver instance on local machine. Selenium WebDriver TestNg Maven

Required. Want to run test cases with multiple instances of driver on local.

 <build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <configuration>
                <source>1.7</source>
                <target>1.7</target>
            </configuration>
        </plugin>
    </plugins>
</build>

testng.xml

<suite name="testSuite" verbose="10" preserve-order="true" configfailurepolicy="continue">

<test name="SanityTest" parallel="none">
    <classes>
        <class name="test.java.HeaderTests"/>
    </classes>
</test>
</suite>

Driver

driver = new InternetExplorerDriver(capabilities);
driver.manage().window().maximize();
driver.get(url);
3
hmm.. what are you looking for, precisely ? have you experimented running your tests with TestNG parallel attributes set and is something not working ?user2611581
thanks for reply. I am precisely looking on how to set driver to run test cases in parallel. Will I have to create multiple instances for different threads? Or can I use single driver instance only?arctic_monkey

3 Answers

0
votes

You must modify your testng.xml file and tell it to run in

<test name="SanityTest" parallel="none">

parallel: class parallel: methods

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

0
votes

It seems that in your testng.xml your parallel value is set to "none". In order to run in parallel you will have to set it to either "class": which will run classes in parallel or "methods": which will run methods regardless of class or package in parallel.

However just a note, its hard to tell how you're handling your driver but you will need to make it thread specific or else your commands may be sent to the wrong driver.

Hope this helps.

0
votes

Based on your question and clarifications, it seems that you are looking to run your tests in parallel. For e.g. - running multiple test classes in parallel so that you can reduce the test execution time. In such a case, it is much more advisable to set up multiple threads of the test runner such as TestNG and NOT multiple threads/instances of the webdriver. Something like this:

    <suite name="Parallel test runs" parallel="tests" thread-count="2"> 
        <test name="test1">
            <classes>
                <class name="com.company.test1" ></class>
            </classes>
        </test>

        <test name="test2">
            <classes>
                <class name="com.company.test2" ></class>
            </classes>
        </test>
    </suite>

This will run test1 and test2 in parallel. With TestNG, you can run methods, classes or groups in parallel. A probably use case for setting up multiple threads for the WebDriver would be a scenario where you want to keep checking for the presence of, say an alert, while the test is running. (I don't personally approve of such a style but I have seen teams doing it). For such an approach to work, test classes should not be interdependent. Additionally, each test should setup (at the beginning) and tear down (at the end of the test) an instance of the Webdriver.