java - 有没有可能在 testng.xml 中并行运行两个 .xml 文件?

标签 java testng saucelabs

我目前有两个不同的 TestSuite(SUITE1.XML 和 SUITE2.xml),具有不同的配置(例如浏览器、操作系统)...

我在 testng.xml 中调用两个套件来在 Saucelabs 上运行...并且运行良好...我唯一关心的是,我希望这些套件并行运行而不是顺序运行...

我得到的输出是

[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} 任务,但是如何实现?我需要一个例子..请帮忙。

我正在使用 macOS 和 TESTNG 6.8.6

最佳答案

另一种选择是使用套件套件。我将在序言中说,自从我使用此设置以来已经有一段时间了,但希望您能在这里找到足够的详细信息,至少可以开始使用。

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

<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 文件:

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

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

此外,两种 XML 类型均支持 <parameter>标签。标准套件 XML 将在 <suite> 处读取两者。并在 <test>水平,我发现<parameter>标签位于<suite>套件 XML 文件上的级别也将起作用。

最后,在执行时,您只需传入 suite-of-suites XML 文件作为套件文件参数。

编辑: 以下是我如何使我的两个套件并行运行。诀窍是设置我的 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 文件都与此配置位于同一目录中。命令行参数和 <suite-file>如果您希望使用目录结构,则需要正确配置条目。

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

说实话,可能有更好的方法来做到这一点。当我尝试做类似的事情时,这正是对我有用的。

关于java - 有没有可能在 testng.xml 中并行运行两个 .xml 文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26810342/

相关文章:

java - 如何在压缩后扩展霍夫曼节点

java - TestNG:如何在命令行上放置 java 方法的参数?

java - 如何使用TestNG编写集成测试来检查JAVA中是否抛出异常?

javascript - 实习生 JS + Saucelabs : Does not start session when using firefox browser

javascript - android 上的酱错误 "Selenium::WebDriver::Error::UnsupportedOperationError: underlying webdriver instance does not support javascript"

java - JOptionPane 确认对话框后 Canvas 右侧和底部出现白条?

使用 jdwp 进行 Java 分析

java - 触发方法每天一次

java - TestNg with groovy,Java 中的错误 ShortTypeHandling

java - 在 SauceLabs 上运行 Android WebDriver 测试