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

大兔子大兔子 提交于 2019-12-28 19:39:21

问题


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


回答1:


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.




回答2:


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>



回答3:


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!



来源:https://stackoverflow.com/questions/26810342/is-there-a-possible-way-to-run-two-xml-files-in-testng-xml-parallel

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!