【问题标题】:TestNG Appium Paralell Runs OrganizationTestNG Appium 并行运行组织
【发布时间】:2016-10-22 08:50:01
【问题描述】:

我正在尝试创建一个 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="methods" 和invocationCount 的注释转换器一起使用,以获得类似的结果(一个方法为每个附加的设备)。

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

【问题讨论】:

    标签: parallel-processing structure testng appium


    【解决方案1】:

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

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

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

    【讨论】:

      猜你喜欢
      • 2017-07-22
      • 2020-03-01
      • 2023-03-31
      • 2020-11-06
      • 1970-01-01
      • 1970-01-01
      • 2022-01-17
      • 2020-08-30
      • 1970-01-01
      相关资源
      最近更新 更多