2

I currently have two different TestSuites (SUITE1.XML and SUITE2.xml) with different configurations (e.g browsers, Os)...

I call both SUITES inside testng.xml to run on saucelabs... and it runs fine... Only what I am concerned is, I want these suites to run parallel instead of sequential...

The output i get is

[TestNG] Running:
  /Users/muzamilabbasi/Automation/BaublebarTest/Suite1.xml

This is Browser String FIREFOX
This is Platform String WIN8
This is Version String 25
This is Browser String FIREFOX
This is Platform String WIN8
This is Version String 25
log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN No appenders could be found for logger (org.apache.http.client.protocol.RequestAddCookies).
log4j:WARN Please initialize the log4j system properly.
Page Title isGoogle
Page Title isGoogle

===============================================
mysuite1
Total tests run: 2, Failures: 0, Skips: 0
===============================================

[TestNG] Running:
  /Users/muzamilabbasi/Automation/BaublebarTest/Suite2.xml

This is Browser String FIREFOX
This is Platform String XP
This is Version String 7
This is Browser String FIREFOX
This is Platform String XP
This is Version String 7
Page Title isGoogle
Page Title isGoogle

I have searched alot of web and mostly answers I got is using ANT {PARALLEL} task I can achieve but how? I need an example.. Please help.

I am using macOS & TESTNG 6.8.6

ceving
  • 21,900
  • 13
  • 104
  • 178
Muzamil Abbasi
  • 49
  • 1
  • 2
  • 6

3 Answers3

8

Another option is to use a suite-of-suites. I'll preface this by saying it's been a while since I've worked with this setup, but hopefully you'll find enough detail here to at least get started.

First, you'd define two (or more) suite XML files:

<suite name="Suite1">
    <test name="test1">
        <classes>
            <class name="fully.qualified.ClassName" />
        </classes>
        <methods>
            <include name="method1" />
        </methods>
    </test>
</suite>

and...

<suite name="Suite2">
    <test name="test2">
        <classes>
            <class name="fully.qualified.ClassName" />
        </classes>
        <methods>
            <include name="method2" />
        </methods>
    </test>
</suite>

Then, you'd define a suite-of-suites XML file:

<suite name="suite of suites">
    <suite-files>
        <suite-file path="Suite1.xml" />
        <suite-file path="Suite2.xml" />
    </suite-files>
</suite>

Do note, that the suite-file path value is the relative path from the current suite-of-suites XML file to the XML file you're calling. If they're in the same directory, simply the file name will suffice.

Additionally, both XML types do support the <parameter> tag. The standard suite XML will read both at <suite> and in the <test> levels, and I've found that <parameter> tags at the <suite> level on the suite-of-suites XML file will work as well.

Finally, on execution, you'd need only pass in the suite-of-suites XML file as your suite file argument.

EDIT: Here's how I was able to make my two suites run in parallel. The trick was setting up my main() method properly.

public class TestRunner
{
    public static void main(String[] args)
    {
        TestNG testng = new TestNG();
        TestListenerAdapter adapter = new TestListenerAdapter();
        List<String> suites = new ArrayList<String>();

        testng.addListener(adapter);
        suites.add(args[0]);
        testng.setTestSuites(suites);
        testng.setParallel("parallel");
        testng.setSuiteThreadPoolSize(5);
        testng.setOutputDirectory("path to output");
        testng.run();
    }
}

Then, on the command line:

java -jar ParallelSuiteDemo.jar SuiteOfSuites.xml

Note, my jar and all xml files were in the same directory with this configuration. The command line args and <suite-file> entries would need to be configured properly if you wish you use a directory structure.

This yielded my two suite.xml files running in parallel on a Selenium Grid.

There may be better ways of doing this, to be honest. This is just what worked for me when I was trying to do something similar.

tim-slifer
  • 1,068
  • 1
  • 9
  • 17
  • Hi Tim, I actually tried this configuration with master & slave suites but the problem is, I am using sauce labs to execute my tests, so lets say I have suites called (SUITE1.xml having 20 test cases and SUite2.xml having 20 testcase) both for different configuration, I called them inside my MasterSUite.xml, what I don't get it its run the SUITE1.xml first after completion of SUITE1.xml it runs SUITE2.xml .... What I want is both (SUITE1.xml & SUITE2.xml) to run at the same time – Muzamil Abbasi Nov 12 '14 at 18:29
  • I see what you're saying. I'll need to go through some old code to find the specifics, but I did have this working just as you describe what you want to see. The only difference, though, was I was running on an internal Grid as opposed to Sauce... though I would think Sauce would work with this sort of thing since the configuration is all in the code. I'll need a few days, but I'll get this back in working order on my end and post my findings in hopes that you can attempt the same with Sauce and get the desired result. I seem to recall that there was an obscure setting someplace for this. – tim-slifer Nov 13 '14 at 07:15
  • I updated my answer to include some new information you may find helpful if you wish to pursue this approach. With the new configurations, I was able to get two suites to run in parallel on my own Grid. There may be other/better ways to do this than what I added above... it's just what worked for be back when I was working with suite-of-suite files. Hopefully this will at least get you started and you can make improvements where you see fit. – tim-slifer Nov 16 '14 at 19:54
  • The command should be: `java -jar TestRunner.jar SuiteOfSuites.xml` – timekeeper May 09 '18 at 14:30
4

You no need to run suits in parallel....instead you can write two tests in single testng.xml suit and can run it in parallel.

If you want to use two different configurations for different tests (browser/os etc) make that as a parameter in testng.xml and use selenium grid to redirect each threads to appropriate nodes

Have look at the below example

<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >

<suite name="Test Suit" verbose="2" parallel="tests">

<test name="Regression Test">
    <parameter name="browser" value="firefox" />
    <parameter name="os" value="win7" />
    <classes>
        <class name="pakagename.classname" />
    </classes>
</test>

<test name="Smoke Test">
    <parameter name="browser" value="chrome" />
    <parameter name="os" value="mac" />
    <classes>
        <class name="pakagename.classname" />
    </classes>
</test>

Also may be you can run two testng.xml suits using ANT or MAVEN. But I prefer 1st one. Please add the below section in pom.xml of your MAVEN project

<build>
    <sourceDirectory>src</sourceDirectory>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-surefire-plugin</artifactId>
            <version>2.17</version>
            <configuration>
                <suiteXmlFiles>
                    <suiteXmlFile>testng1.xml</suiteXmlFile>
                    <suiteXmlFile>testng2.xml</suiteXmlFile>
                </suiteXmlFiles>
                <reportsDirectory>${basedir}/src/test/java/</reportsDirectory>
             <testFailureIgnore>true</testFailureIgnore>
            </configuration>
        </plugin>
      <plugins>
<build>
Babulu
  • 334
  • 4
  • 16
  • Bharat I haven't given it a shot, I am avoiding to use maven as we have ANT, so I will see if I can fit into ANT somewhere, if you could help will appreciate.. – Muzamil Abbasi Nov 12 '14 at 18:32
  • @Muzamil: I have not worked in ANT. You can try 'tim-slifer' solution, invoke it from ANT. To run slave xmls in parallel using master xml add '' in your master xml. Again I am not sure this will serve your purpose, just a hint. – Babulu Nov 13 '14 at 04:26
  • Thanks Bharat, I will surely try it – Muzamil Abbasi Nov 14 '14 at 19:32
0

Yes, you can do this by using "suitethreadpoolsize" attribute of testng

<suite-files suitethreadpoolsize="2">
    <suite-file path="suite1.xml" />
    <suite-file path="suite2.xml" />
</suite-files>

Refer the testng's official website for more details http://testng.org/doc/documentation-main.html#parallel-running

Thanks!

A. K. Sahu
  • 271
  • 3
  • 2
  • Can you bit elaborate how did you exactly use the above xml tags? Getting error "Attribute "suitethreadpoolsize" must be declared for element type "suite- files"." and not allowing to run. – Uday Oct 12 '20 at 08:35