我想使用Selenium Grid多次运行相同的TestNG套件(用于负载测试)。 例如,我有一个包含3种不同浏览器的节点。 Selenium Grid允许在许多线程中运行多个不同的测试套件,但我无法弄清楚如何在不同浏览器的多个线程中运行相同的测试套件。
可能还有其他一些方法可以并行运行整个测试套件。
答案 0 :(得分:1)
最新版本的TestNG现在为您提供了一个名为IAlterSuiteListener
的新侦听器,您可以使用该侦听器逐字克隆var x = [
"Nation Flags",
"Landmarks",
"Smash",
"History",
"Famous People",
"Word Find",
"Quiz",
"Test Your Knowledge"]
var y: [AnyObject] = [Int(true), Int(false), Int(true), Int(false), Int(false),Int(false),Int(false),Int(false),]
var challengesArray: [AnyObject] = [AnyObject]()
for (index, value) in x.enumerate() { // <-- here is the new loop
var Challenge: [NSObject : AnyObject] = [
"challenge" : x[index],
"status" : y[index]
]
challengesArray.append(Challenge)
}
对象(XmlSuite
表示XML中的套件标记)。所以也许你可以使用那个听众并通过你的听众复制一个套件&#34; n&#34;时间根据您的需要而定。
答案 1 :(得分:1)
我使用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() {
}
}
答案 2 :(得分: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>