Selenium网格,当并行运行时,测试开始在同一线程上启动



使用selenium grid和TestNg运行并行测试,@BeforeTest方法似乎在同一个线程上启动两个测试,有什么想法吗?我试图确保每个测试类都在自己的线程上启动。

@BeforeTest(alwaysRun = true)
@Parameters({ "selenium.OS", "selenium.browser","selenium.testClassNameHere" })
public void beforeTest(String OS, String browser, String testClassNameHere) {
    Out.trace("Starting beforeTest for "+testClassNameHere+" on thread:  " + Thread.currentThread().hashCode());
    //create driver here
    Out.trace("beforeTest has finished");
}

然而,这里是日志,显示两个测试类在同一个线程上启动,并且只创建了两个驱动程序,这导致了侦听器和报告的各种头痛。

TRACE: Starting beforeTest for AcceptanceTests.ErrorReportingTests on thread:  777376239
TRACE: Starting beforeTest for AcceptanceTests.PopupTests on thread:  777376239
TRACE: Starting beforeTest for AcceptanceTests.LoginPageTests on thread:  1235740568
TRACE: Finished making driver.
TRACE: Finished making driver.
TRACE: beforeTest has finished
TRACE: beforeTest has finished

下面是ANT xml文件,显示了三个测试类…

<?xml version="1.0"?>
<suite name="Debugging QA Tests" parallel="tests" thread-count="10">
   <test name="Popup Tests" preserve-order="true" >
        <parameter name="selenium.OS" value="localhost" />
        <parameter name="selenium.browser" value="chrome" />
        <parameter name="selenium.testClassNameHere" value="AcceptanceTests.PopupTests" />
        <classes>
            <class name="qaautomation.AcceptanceTests.PopupTests" />
        </classes>
    </test>
  <test name="Login Page Tests" preserve-order="true">
        <parameter name="selenium.OS" value="localhost" />
        <parameter name="selenium.browser" value="chrome" />
        <parameter name="selenium.testClassNameHere" value="AcceptanceTests.LoginPageTests" />
        <classes>
            <class name="qaautomation.AcceptanceTests.LoginPageTests" />
        </classes>
    </test>
    <test name="Error Reporting Tests" preserve-order="true">
        <parameter name="selenium.OS" value="localhost" />
        <parameter name="selenium.browser" value="chrome" />
       <parameter name="selenium.testClassNameHere" value="AcceptanceTests.ErrorReportingTests" />
         <classes>
            <class name="qaautomation.AcceptanceTests.ErrorReportingTests" />
        </classes>
    </test>
</suite> 

您在哪个类中定义了beforeTest方法?我已经创建了相同的结构,下面的代码是为我工作在不同的线程。

public class TestCase {
    @BeforeTest(alwaysRun = true)
    @Parameters({ "selenium.OS", "selenium.browser","selenium.testClassNameHere" })
    public void beforeTest(String OS, String browser, String testClassNameHere) {
        System.out.println("Starting beforeTest for "+testClassNameHere+" on thread:  " + Thread.currentThread().hashCode());
        //create driver here
        System.out.println("beforeTest has finished");
    }
}
public class PopupTests extends TestCase{
    @Test(description="popup reporting")
    public void teszt()
    {
        System.out.println("popup");
    }
}
public class ErrorReportingTests extends TestCase{
    @Test(description="error reporting")
    public void teszt()
    {
        System.out.println("Error");
    }
}
public class LoginPageTests extends TestCase {
    @Test(description="login reporting")
    public void teszt()
    {
        System.out.println("Login");
    }
}

我使用了与您给出的相同的测试xml配置文件,以下是我的输出。

Starting beforeTest for AcceptanceTests.ErrorReportingTests on thread:  1968879864
beforeTest has finished
Starting beforeTest for AcceptanceTests.LoginPageTests on thread:  88161428
beforeTest has finished
Starting beforeTest for AcceptanceTests.PopupTests on thread:  1040963230
beforeTest has finished
Login
popup
Error

相关内容

  • 没有找到相关文章

最新更新