与Selenium Grid并行运行TestNG套件



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

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

最新版本的

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

我使用 TestNG 的@Factory@DataProvider来并发运行我的测试,每个浏览器多次运行我的测试,如下所示:

基本测试类:

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()+"] ###");
    } 
}

测试类:

public class ITlogin extends AbstractIntegrationTest {
    @Factory(dataProvider = "environment")
    public ITlogin(Environments environments) {
        super(environments);
    }
    @Test
    public void whenLoginWithValidUser_HomePageShouldBeVisible() {
    }
}

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

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

您可以参考 TestNG 文档了解更多详细信息。

您可以在 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>

最新更新