TestNG:并行执行:只有活动窗口完成测试

编程入门 行业动态 更新时间:2024-10-09 08:28:11
本文介绍了TestNG:并行执行:只有活动窗口完成测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送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:关键词]

本文发布于:2023-04-30 22:04:19,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1400869.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:窗口   测试   TestNG

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!