2016-05-20 96 views
0

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

也许有些其他方法可以并行运行整个测试套件多次。

+0

你如何触发你的测试? –

+0

我使用TestNG的注释(没有的testng.xml)和Maven的万无一失,插件与配置: 10

+0

只是好奇 - 为什么不能有多个作业?发送浏览器名称作为参数? - http://maven.apache.org/surefire/maven-surefire-plugin/examples/testng.html –

回答

1

TestNG的最新版本,现在给你一个使用,你可以从字面上现在克隆XmlSuite对象(XmlSuite代表你的XML套件标签)称为IAlterSuiteListener新听众。所以,也许你可以使用这个监听器,并通过你的监听器根据你的需要复制一个“n”次的套件。

+0

你 - 上面复制。 posti时不需要“@”回答这个问题。 – Jamal

+0

克里希南,谢谢你的建议。我设法在运行时重复测试,就像你在这里的例子:https://github.com/cbeust/testng/blob/master/src/test/java/test/listeners/AlterSuiteListenerTest.java 我也尝试克隆整个XmlSuite对象并将其添加到套件列表。 它的工作原理,但我不能在一个单独的线程运行复制套件。假设我们有一个套件A并创建一个克隆A1。当我运行测试时,尽管配置 10,套件仍会连续触发。 –

+0

最大:您可以通过万无一失插件与下面条目做 org.apache.maven.plugins 行家-万无一失-插件 2.19.1 <结构> 的src /测试/资源/的testng.xml suitethreadpoolsize

0

假设您的实现是线程安全的,并且您指向远程驱动程序中的网格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> 
+0

是的,它允许并行运行测试。但问题是如何多次调用测试套件。 我的测试套件是作为一个复杂的场景与依赖测试构建的。我想要并行运行整个场景(即套件)多次。我知道有invocationCount参数,但它仅适用于方法。 –

+0

您可以通过在xml套件文件中多次重复xml测试并使用并行运行测试来使用技巧。例如: \t \t \t \t \t \t <测试名称= “TestOnChrome”> \t <参数名称= “driver.name” 值= “chromeDriver”/> \t \t <! - 真的> \t user861594

+0

这是可能的,但我想有动态配置而且我有很多套房(带注释进行配置),它是不方便他们每个人多次重复 –

0

我使用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() { 
    } 
} 
相关问题