java - 如何在没有硒网格的情况下在多个浏览器实例中并行运行单个测试用例
问题描述
我正在建立一个框架并希望在多个浏览器实例中并行运行单个测试方法(点击 url 然后执行一些操作)(例如:通过同时打开〜5 个 chrome 浏览器实例来点击一个 url)
我之前已经能够并行运行不同的测试方法,但我想一次多次运行单个测试用例(并行)
GoogleTest.java
@Test(invocationCount=2)
public void hitUrl() throws Exception {
WebDriver driver = getDriver();
driver.get("https://google.com");
}
测试NG.xml
<suite thread-count="2" verbose="2" name="Gmail Suite"
annotations="JDK" parallel="methods">
<test name="Google_Test">
<classes>
<class name="big.GoogleTest">
<methods>
<include name="hitUrl" />
</methods>
</class>
</classes>
</test>
我希望一次打开两个 chrome 浏览器实例,但它们一个接一个地在单个浏览器实例中运行。
解决方案
使用@Test(invocationCount= int Values)
它将在同一浏览器中针对指定值运行您的代码。
您可以在每次要运行该类时创建一个节点,然后按test
. 您还希望将并行化属性移动到<suite>
节点。例如:
测试NG.xml
<suite name="ParallelTestingGoogle" verbose="1" parallel="tests" thread-count="5">
<test name="1st">
<classes>
<class name="packageName.className"/>
</classes>
</test>
<test name="2nd">
<classes>
<class name="packageName.className" />
</classes>
</test>
<test name="3rd">
<classes>
<class name="packageName.className" />
</classes>
</test>
<test name="4th">
<classes>
<class name="packageName.className" />
</classes>
</test>
<test name="5th">
<classes>
<class name="packageName.className" />
</classes>
</test>
</suite>
爪哇:
public class TC1 {
WebDriver driver;
@Test
public void testCaseOne() {
// Printing Id of the thread on using which test method got executed
System.setProperty("webdriver.chrome.driver", "your ChromeDriver path");
driver = new ChromeDriver();
driver.get("https://www.google.com");
}
}
推荐阅读
- swift - 动态编程斐波那契斯威夫特
- python - 从 python 脚本设置 bash 环境变量
- php - 对 html php mysql 表进行排序的问题
- mysql - 从 MySQL 中的 2 个不同的表中创建一个别名列
- html - 对 UL 和 Flex CSS 感到困惑,2 行,2 列,共 4 项
- pandas - 使用 Pandas 时,空列在列表命令中列出
- if-statement - 已声明且未使用 - 如何更新 IF 语句中的变量
- java - JSF - 在 Ajax 调用中返回数据
- jdbc - Vertx JDBCClient 与 HttpVerticle 超时
- git - 如何将背面项目合并到已经存在的 github 存储库