有没有办法在testng.xml并行运行两个.xml文件? [英] Is there a possible way to run two .xml files in testng.xml parallel?

查看:325
本文介绍了有没有办法在testng.xml并行运行两个.xml文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前有两个不同的TestSuite(SUITE1.XML和SUITE2.xml),配置不同(例如浏览器,Os)......

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

我把两个SUIT都称为testng.xml在saucelabs上运行......它运行良好......只有我关心的是,我希望这些套件能够并行运行而不是顺序...

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...

我得到的输出是


[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

我搜索了很多网页,而且我得到的答案主要是使用我可以实现的ANT {PARALLEL}任务,但是如何?我需要一个例子..请帮忙。

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.

我正在使用macOS& TESTNG 6.8.6

I am using macOS & TESTNG 6.8.6

推荐答案

另一个选择是使用套件套件。我会说这已经有一段时间了,因为我已经使用了这个设置,但希望你能在这里找到足够的细节至少开始。

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.

首先,您要定义两个(或更多)套件XML文件:

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>

和...

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

然后,您将定义一套套件XML文件:

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>

请注意, suite-file path value是从当前套件XML文件到您正在调用的XML文件的相对路径。如果它们位于同一目录中,只需文件名即可。

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.

此外,两种XML类型都支持< parameter> 标签。标准套件XML将在< suite> 以及< test> 级别读取,并且我'我们在套件套件XML文件的< suite> 级别找到了< parameter> 标签也将工作。

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.

最后,在执行时,您只需要传递套件套件XML文件作为套件文件参数。

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

编辑:
这是我能够让我的两个套件并行运行的方式。诀窍是正确设置我的 main()方法。

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();
    }
}

然后,在命令行上:

java -jar ParallelSuiteDemo.jar SuiteOfSuites.xml

注意,我的jar和所有xml文件都与此配置位于同一目录中。如果您希望使用目录结构,则需要正确配置命令行参数args和< suite-file> 条目。

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.

这产生了我在Selenium Grid上并行运行的两个suite.xml文件。

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.

这篇关于有没有办法在testng.xml并行运行两个.xml文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆