繁体   English   中英

使用硒网格测试并行执行测试

[英]Parallel execution of tests using selenium grid testng

我在一个类中有5到6个方法,并且想在不同的节点上并行运行方法。 我有2个节点的网格2设置。

在我的testng.xml下面找到

<suite name="Test" parallel="methods"  thread-count="2">

    <test name="Test1">
        <classes>
             <class name="test.LoginTest"/>
        </classes>
    </test>

</suite>

我有一个测试工具,它利用了login,common和utils类

Public class TestHarness{
public WebDriver driver = null;
public DesiredCapabilities cap = null;

public Login login;
public Common common;
    public void initilize(){
        cap = DesiredCapabilities.firefox();
                cap.setBrowserName("firefox");
                cap.setPlatform(Platform.ANY);
        driver = new RemoteWebDriver(new URL(CONFIG.getProperty("hub")),cap);

        common = new Common(driver);
        login = new Login(driver);
        utils = new Utils(driver);

    }

}

在测试类中,我扩展了测试工具,在@BeforeMethod中,我调用了intilize方法

public class LoginTest extends TestHarness{

    @BeforeMethod
    public void startTest() {

        initilize();
        login.loginAsAdmin();
    }

    @Test
    public void testLoginWithCorrectPassword(){
        common.goToAdminSettings();
    }

    @Test
    public void testLoginwithInCorrectPassword(){
        utils.getMessage();
    }
}

如果运行测试,我会看到以下问题

两种浏览器正在每个节点中打开一个,但是只有一个浏览器会启动该应用程序,而另一个则不会。

让我知道我是否想念什么?

谢谢

1)您确定自己正在运行正确的测试课程吗?

<class name="test.LoginTest"/>

您的测试在:

public class Testing123 extends TestHarness{

2)您的代码未显示驱动程序的声明。 确保此字段不是静态的

3)另外,检查网格实际配置为处理的内容: http:// localhost:4444 / grid / admin / AllNodes

4)将测试配置中的线程数提高到4。

即使驱动程序是非静态的,它也可以在测试方法之间共享,因为它们是从同一类实例调用的

让我们将测试方法放在单独的类中

a)将@BeforeMethod移到TestHarness类

b)建立

public class LoginTest2 exteds TestHarness 

并在那里移动第二个@Test方法

c)修改套件:

<suite name="Test" parallel="classes"  thread-count="2">

<test name="Test1">
    <classes>
         <class name="test.LoginTest"/>
         <class name="test.LoginTest2"/>
    </classes>
</test>

如果这将帮助最终解决方案,可以使用ThreadLocal,如下所示:

平行的webdriver-处决-使用-TestNG的

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM