【问题标题】:TestNG: Parallel Execution: Only active window complete the testTestNG:并行执行:只有活动窗口才能完成测试
【发布时间】:2021-02-02 01:52:54
【问题描述】:

我已经使用 TestNG 设置了一个 selenium Web 驱动程序测试来执行并行执行。测试开始正常,这意味着所有测试在不同的浏览器窗口中同时开始,但只有处于活动状态的窗口(在顶部)完成测试,其后面的所有其他窗口将停止。有谁知道为什么?这是示例 XML。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "https://testng.org/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 -->

【问题讨论】:

    标签: java selenium testng


    【解决方案1】:

    实际上需要更多信息..你使用网格吗?首先启动集线器和节点

    首先启动集线器

    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 而不是本地主机

    这里是 doc https://www.selenium.dev/documentation/en/grid/ 最好的学习场所

    现在,需要基类来获取 webdriver 实例

     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();
    
     }
     }
    

    在这里了解 chrome 选项https://chromedriver.chromium.org/capabilities

    现在,简单测试

     public class Test01 extends BaseTest{
    
    @Test
    public void testLink()throws Exception{
        getDriver().get("url");
        //to all stuff
       }
    }
    

    【讨论】:

      猜你喜欢
      • 2017-01-17
      • 2019-02-01
      • 1970-01-01
      • 2017-06-15
      • 2022-01-25
      • 1970-01-01
      • 2020-07-16
      • 1970-01-01
      • 2014-04-04
      相关资源
      最近更新 更多