TestNG Selenium Grid 2 未并行运行测试 [英] TestNG Selenium Grid 2 not running tests in parallel

查看:36
本文介绍了TestNG Selenium Grid 2 未并行运行测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在尝试使用 TestNG 和 Selenium Grid 2 并行运行测试时,我似乎遇到了问题.

I seem to be having an issue when attempting to run tests in parallel using TestNG alongside Selenium Grid 2.

虽然打开了正确数量的浏览器以匹配我正在运行的测试数量,但所有测试的所有指令都被触发到同一个浏览器窗口.例如,每个测试将打开一个页面并尝试登录.将打开四个浏览器窗口,但一个浏览器窗口将导航到登录页面四次,然后输入用户名 4 次,而其余浏览器窗口保持不变不活动.

Although the right number of browsers are opened to match the amount of tests that I'm running , all instructions for all tests are being fired to the same browser window. For example, each test will open a page and attempt to log in. Four browser windows will open, but one browser window will navigate to the login page four times and then type the username in 4 times, whilst the rest of the browser windows remain inactive.

这是我开始网格的方式:

Here's how I'm starting grid:

java -jar selenium-server-standalone-28.0.jar -role hub
java -jar selenium-server-standalone-28.0.jar -webdriver.chrome.driver="*location*/chromedriver_mac" -role node 

这是套件 xml 的设置方式:

This is how the suite xml is set up:

<suite name="testng" verbose="1" parallel="classes">
    <test name="chrome">
        <packages>
            <package name="login"/>
            <package name="lists"/>
        </packages>
    </test>
</suite>

以下是测试布局的示例:

And here's an example of how the tests are laid out:

public class login_logout extends TestBase {
    @Test
    public void login(){
        //initiates login page object and call super user login
        LoginPage login = LoginPage.navigateTo(driver, base_url)
        LoggedInPage loggedIn = login.superuserlogin();
        }
    }

测试基地布局如下:

public class TestBase {
    public static WebDriver driver;
    public static DesiredCapabilitiess capabilities;
    @BeforeClass
    public static void setUp(){
        base_url = "*login page url*;
        capabilities = DesiredCapabilities.chrome();
        driver = new RemoteWebDriver(capabilities);
        driver.get(base_url);
    }
}

我遗漏了一些很明显的东西,但任何帮助将不胜感激.

It's probably something really obvious that I'm missing but any help would be appreciated.

提前致谢.

推荐答案

驱动程序对象是静态的.所以你有 4 个初始化发生,4 个浏览器启动,但驱动程序是静态的,它只保存对最后一个初始化浏览器的引用,因此你的所有命令都是针对同一个驱动程序执行的.您可以尝试为并行运行探索 Threadlocal 对象.

The driver object is static. So you have 4 initializations happening and 4 browsers launching but the driver being a static , it would hold only the reference to the last initialized browser and hence all your commands are being executed against the same driver. You can try exploring Threadlocal objects for your parallel runs.

这篇关于TestNG Selenium Grid 2 未并行运行测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆