简体   繁体   中英

Run selenium test cases in parallel, using testng | maven

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);

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/

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.

Based on your question and clarifications, it seems that you are looking to run your tests in parallel. For eg - 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM