问题描述
限时送ChatGPT账号..我已经使用 TestNG 设置了一个 selenium Web 驱动程序测试来执行并行执行.测试开始正常,这意味着所有测试在不同的浏览器窗口中同时开始,但只有处于活动状态(位于顶部)的窗口完成测试,其后的所有其他窗口将停止.有谁知道为什么?这是示例 XML.
<?xml version="1.0";编码=UTF-8"?><!DOCTYPE套件系统"https://testng/testng-1.0.dtd><套件名称=套件"并行=类"线程数=2"><测试名称=测试"><类><类名=TestCase1.ProcessWorkflow1";/><类名=TestCase2.ProcessWorkflow2";/></classes></测试><!-- 测试--></套房><!-- 套房 -->
解决方案 实际上需要更多信息.. 你在使用网格吗?首先启动集线器和节点
首先启动集线器
java -jar selenium-server-standalone-3.XX.XX.jar -role hub
然后启动节点
java -Dwebdriver.chrome.driver=C:\chromedriver.exe"-jar selenium-server-standalone-3.XX.XX.jar -role webdriver -hub http://localhost:4444/grid/register
我刚刚添加了 chrome 驱动程序,你也可以添加其他驱动程序并使用网格/集线器启动的机器的 ip 而不是本地主机
这里是文档 https://www.selenium.dev/documentation/en/grid/ 最好的学习场所
现在,需要基类来获取 webdriver 实例
公共类 BaseTest {受保护的 ThreadLocal线程驱动程序 = 空;@前方法public void setUp() 抛出 MalformedURLException {threadDriver = new ThreadLocal();hromeOptions 选项 = 新 ChromeOptions();driver = new RemoteWebDriver(new URL("http://10.x.x.x:4444/wd/hub"), options);threadDriver.set(驱动程序);}公共 WebDriver getDriver() {返回 threadDriver.get();}@AfterMethod公共无效关闭浏览器(){getDriver().quit();}}
了解 chrome 选项的地方 https://chromedriver.chromium/capabilities>
现在,简单的测试
公共类 Test01 扩展 BaseTest{@测试public void testLink()抛出异常{getDriver().get("url");//所有的东西}}
I have setup a selenium Web driver test with TestNG to perform Parallel execution. The test starts ok, meaning that all tests start at the same time in different browser windows, but only the window, which is active (on the top), completes the test and all the other windows behind it will just stop. Does anyone know why? This is the sample XML.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng/testng-1.0.dtd">
<suite name="Suite" parallel = "classes" thread-count="2" >
<test name="Test">
<classes>
<class name = "TestCase1.ProcessWorkflow1" />
<class name = "TestCase2.ProcessWorkflow2" />
</classes>
</test> <!-- Test -->
</suite> <!-- Suite -->
解决方案
bit more information is required actually.. are u using grid? first start hub and node
First start the hub
java -jar selenium-server-standalone-3.XX.XX.jar -role hub
then start the node
java -Dwebdriver.chrome.driver="C:\chromedriver.exe" -jar selenium-server-standalone-3.XX.XX.jar -role webdriver -hub http://localhost:4444/grid/register
i just added chrome driver, u can add others too and use ip of machine where grid/hub started instead of localhost
here is doc https://www.selenium.dev/documentation/en/grid/ best place to learn
Now, need base class to get webdriver instance
public class BaseTest {
protected ThreadLocal<RemoteWebDriver> threadDriver = null;
@BeforeMethod
public void setUp() throws MalformedURLException {
threadDriver = new ThreadLocal<RemoteWebDriver>();
hromeOptions options = new ChromeOptions();
driver = new RemoteWebDriver(new URL("http://10.x.x.x:4444/wd/hub"), options);
threadDriver.set(driver);
}
public WebDriver getDriver() {
return threadDriver.get();
}
@AfterMethod
public void closeBrowser() {
getDriver().quit();
}
}
here place to know chrome options https://chromedriver.chromium/capabilities
Now, simple test
public class Test01 extends BaseTest{
@Test
public void testLink()throws Exception{
getDriver().get("url");
//to all stuff
}
}
这篇关于TestNG:并行执行:只有活动窗口完成测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
更多推荐
[db:关键词]
发布评论