首页 文章

TestNG Appium Paralell运行组织

提问于
浏览
0

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

Parent

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

Child

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

Factory

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 =“methods”和invocationCount的注释变换器一起使用,以实现类似的结果(每个附加的一个方法运行设备) .

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

1 回答

  • 0

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

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

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

相关问题