运行 TestNG 套件与 Selenium Grid 并行

Running TestNG suite in parallel with Selenium Grid

我想 运行 使用 Selenium Grid 多次使用同一个 TestNG 套件(用于负载测试)。 例如,我有一个节点有 3 个不同的浏览器。 Selenium Grid 允许在许多线程中 运行 多个 不同 测试套件,但我不知道如何 运行 相同 在不同浏览器的多线程中测试套件。

可能存在一些其他方法 运行 整个测试套件并行多次。

假设您的实现是线程安全的,并且您指向远程驱动程序中的网格 url。你可以在你的 testNG 配置文件中配置它。有多种方法可以配置它。下面是最简单的例子:

<suite name="Sample suite" verbose="0" parallel="methods" thread-count="3">
...
</suite>

详情请参考TestNG Documentation

您可以在 xml 套件文件中重复 xml 多次测试,并并行进行 运行 测试。例如:

<suite name="Sample suite" verbose="0" parallel="tests">
    <test name="TestonFF">
        <parameter name="driver.name" value="firefoxDriver" />
    </test>
    <test name="TestOnChrome"> <!-- test name must be unique -->
        <parameter name="driver.name" value="chromeDriver" /> 
<!-- copied above --> 
    </test> 
</suite>

最新版本的 TestNG 现在为您提供了一个名为 IAlterSuiteListener 的新侦听器,您现在可以使用它从字面上克隆 XmlSuite 对象(XmlSuite 代表您的 XML).因此,也许您可​​以使用该侦听器并通过您的侦听器根据需要复制套件 "n" 次。

我同时使用 TestNG 的 @Factory@DataProvider 到 运行 我的测试和每个浏览器多次这样:

基础测试class:

public abstract class AbstractIntegrationTest extends TestNG { 

    @DataProvider(name = "environment", parallel = true)
    public static Object[][] getEnvironments() { return PropertiesHelper.getBrowsers() ; }

    public AbstractIntegrationTest(final Environments environments) {

        this.environment = environments;
    }

    @BeforeMethod(alwaysRun = true)
    public void init(Method method) {

        this.selenium = new Selenium();
        this.propertiesHelper = new PropertiesHelper();

        this.driver = selenium.getDriverFor(environment);

        login(driver);

        LOGGER.log(Level.INFO, "### STARTING TEST: " + method.getName() +"["+environment.toString()+"] ###");
    } 
}

测试class:

public class ITlogin extends AbstractIntegrationTest {

    @Factory(dataProvider = "environment")
    public ITlogin(Environments environments) {
        super(environments);
    }

    @Test
    public void whenLoginWithValidUser_HomePageShouldBeVisible() {
    }
}