0
votes

I have following suite xml for running UI test using Webdriver:

 <suite name="test suite" verbose="3" parallel="classes" thread-count="2">

<test name="extended_smoke_test_suite">
    <listeners>
        <listener
            ...
        </listener>
    </listeners>   
    <groups>
        <run>
            <include name="somegroup1" />
            <include name="somegroup2" />
        </run>
    </groups>
    <packages>
           <package name="tests.*" ></package>
    </packages>
</test>

When I run this suite, it launches few browsers(more then 2) and I can observe that it works only in two of them. Looks like it starts some test class(TestClass1), execute one of test methods and then switches to another class(TestClass2). After completing test method in TestClass2 it returns back to TestClass1 and continue with it As I have lots of test classes this results in multiple opened browser.

Is there any way to "say" TestNG to execute all tests from TestClass1 and only after that switch to next, so we will have only two opened and active browsers at current moment

2

2 Answers

0
votes

It seems to me to resolve this issue you should investigate in maven surefire plugin direction. Currently i use it for excluding my test suite on build.

pom.xml in my local module

 <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-surefire-plugin</artifactId>
                <version>2.11</version>
                <dependencies>
                    <dependency>
                        <groupId>org.apache.maven.surefire</groupId>
                        <artifactId>surefire-junit47</artifactId>
                        <version>2.12</version>
                    </dependency>
                </dependencies>
                <configuration>
                    <!--<includes>-->
                        <!--<include>**/*.class</include>-->
                    <!--</includes>-->
                    <excludedGroups>com.exadel.rms.selenium.SeleniumTests</excludedGroups>

                </configuration>
            </plugin>

I annotate my test class to exlude with

 @Category(SeleniumTests.class)
    public class HomePageTestSuite extends BaseSeleniumTest {
............

And the whole structure you can see on the picture: enter image description here

Actually you can get some useful info for here

Look also this topic. Prolly it can be also useful: JUnit: Can (should) this be done?

Hope this helps you)

0
votes

You have setup your TestNG configuration to run tests parallel:

<suite name="test suite" verbose="3" parallel="classes" thread-count="2">

If you have only two classes: TestClass1 and TestClass2, then TestNG will create 2 threads and will invoke tests from TestClass1 in one thread, and TestClass2 in the other.

If you want TestClass2 run after TestClass1 you have several options:

1.Make class TestClass2 dependant on TestClass1. There multiple options here, so just refer to Dependcies section of TestNG documentation.

2.Set thread-count="1" and parallel="false" (or remove parallel attribute). Also make sure you don't have preserve-order="false" and put your TestClass2 after TestClass1 in xml.

<test name="extended_smoke_test_suite">
    <classes>
        <class name="test.TestClass1"/>
        <class name="test.TestClass2"/>
    </classes>
</test>