How to run Parallel tests by groups using Maven and TestNG?

25 Views Asked by At

I have different tests in different classes which I want to run in 2 different devices using Appium. So as you can see I have some tests for iPhone 1 and other tests for iPhone 2. There is also some groups like "Regression" or "Smoke"

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Parallel" thread-count="2" parallel="tests">
    <listeners>
        <listener class-name="config.utils.RetryListener" />
    </listeners>

    <test name="iPhone15 I">
        <parameter name="os" value="ios"/>
        <parameter name="deviceIndex" value="1"/>
        <parameter name="networkLogs" value="true"/>
        <groups>
            <run>
                <include name="Smoke"/>
                <include name="Release"/>
            </run>
        </groups>
        <classes>
            <class name="tests.ios.Account"/>
            <class name="tests.ios.CreateTeam"/>
            <class name="tests.ios.Roster"/>
        </classes>
    </test>

    <test name="iPhone15 II">
        <parameter name="os" value="ios"/>
        <parameter name="deviceIndex" value="2"/>
        <parameter name="networkLogs" value="true"/>
        <groups>
            <run>
                <include name="Smoke"/>
                <include name="Release"/>
                <include name="Advertisements"/>
            </run>
        </groups>
        <classes>
            <class name="tests.ios.Schedule"/>
            <class name="tests.ios.Ads"/>
        </classes>
    </test>
</suite>

When I try to run via GitHub Actions by Maven command, for example: mvn clean test -Pios -Dgroups=Smoke, the tests fail to run by the group I picked. It simply run random tests.

I am not sure if I am suppose to set Surefire plugin properly on pom.xml OR if the way I am setting the groups with tag <include> are not correct for this scenario of parallel testing

Here's how my pom.xml file looks like:

            <build>
                <plugins>
                    <plugin>
                        <groupId>org.apache.maven.plugins</groupId>
                        <artifactId>maven-surefire-plugin</artifactId>
                        <version>2.22.2</version>
                        <configuration>
                            <testFailureIgnore>true</testFailureIgnore>
                            <suiteXmlFiles>
                                <suiteXmlFile>test_ios.xml</suiteXmlFile>
                            </suiteXmlFiles>
                        </configuration>
                    </plugin>
                </plugins>
            </build>

Does anyone have a suggestion for this issue? Thank you!

I tried to change the parallel tag from tests to methods - didnt work. Also setting the parallel tag within test tags - didnt work either

0

There are 0 best solutions below