TestNG Appium Paralell运行组织

时间:2016-06-21 00:08:04

标签: parallel-processing structure testng appium

我正在尝试创建一个testNG套件,用于在多个设备上同时使用Appium运行测试。我目前正在使用@BeforeSuite为每个设备设置服务器/驱动程序,然后使用@BeforeMethod和@AfterMethod函数将连接分发给测试方法。我有一个主套件套件.xml,可以调用与我的每个测试类关联的不同子.xml文件。测试类分别与@Factory相关联,这允许我并行运行实例(根据连接设备的数量在运行时决定)。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Default Suite">
  <parameter name="other" value="@SOMETHING@"></parameter>
  <suite-files>
    <suite-file path="src/first.xml" />
    <suite-file path="src/second.xml" />
  </suite-files>
</suite>

儿童

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="first" parallel="instances">
  <test name="android">
    <classes>
      <class name="TestFactory" />
    </classes>
  </test>
</suite>

工厂

public class TestFactory {

    @Factory
    public Object[] initial() {
        int numDevices = DeviceManager.getNumAttachedDevices();
        Object[] result = new Object[numDevices];
        for (int i = 0; i < numDevices; i++) {
            result[i] = new StartupTest();
        }

        return result;
    }
}

我绝对不想这样做。我需要为每个我想要的测试类创建一个新的@Factory类,这似乎很荒谬。我最近发现我可以在@DataProvider中使用parallel = true,它可以与paralell =&#34;方法&#34;一起使用。和invocationCount的注释转换器,以实现类似的结果(每个连接的设备运行一个方法)。

我不确定我的@BeforeMethod和@AfterMethod调用如何用于在正确的设备上执行所需的设置和清理(它们将缺少设备名称)。有没有其他推荐的方法来做到这一点?或者这是我最好的选择?

1 个答案:

答案 0 :(得分:0)

事实证明,我可以在测试类中使用我的@Factory方法,而不是完全单独创建一个类。

据我所知,在parallel =“methods”上控制TestNG线程并不简单,因此它们在运行单个方法后都会加入。没有这种能力,使用@DataProvider似乎要复杂得多(而且不值得)。

在我的@Factory中,我仍然可以为每个实例传递自定义参数。