Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
261 views
in Technique[技术] by (71.8m points)

java - Is there a possible way to run two .xml files in testng.xml parallel?

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...