无法使用selenium网格打开多个浏览器实例

时间:2013-10-29 17:04:54

标签: selenium

我正在使用selenium grid(JUNIT,Java)在浏览器的mutli实例上运行我的测试用例。 我使用“java -jar selenium-server-standalone-2.20.0.jar -role hub”来运行hub。 和“java -jar selenium-server-standalone-2.20.0.jar -role webdriver -hub http:// machineip:4444 / grid / register -port 5566”来运行节点。

我确认两者都运行良好。

但是当我通过eclipse运行testcase时,只有一个浏览器打开了。

我使用了这段代码。

    @Test
public void method() throws MalformedURLException {
    baseUrl = "https://www.google.co.in";
    nodeUrl = "http://`machinip`:5566/wd/hub";
    DesiredCapabilities capability = DesiredCapabilities.firefox();
    capability.setBrowserName("firefox");
    capability.setPlatform(Platform.WINDOWS);
    driver = new RemoteWebDriver(new URL(nodeUrl), capability);
    // WebDriver driver = new FirefoxDriver();
    driver.get(baseUrl);
    driver.findElement(By.xpath("//td/div/input")).sendKeys("lucky");
}

请有人建议我如何为单次测试打开多个实例。

提前感谢您的帮助。

2 个答案:

答案 0 :(得分:1)

你测试代码看起来很好 - 对于单个测试) 我认为你错过了运行测试的方式 - 如果你一次运行它就会打开一个实例。 在testNg中,您可以使用dataprovider(参数化)多次运行它,并在tests.xml中指定您想要“parallel = methods”,这样所有的“参数化”测试实例将一起运行。 还要确保你在节点起始行(或你想要的任何数字)中有-browser maxInstances = 5。

efficient selenium testing lab

[披露:我在拉维罗工作]

答案 1 :(得分:0)

尝试在启动服务器时添加此标记 -browser maxInstances = 5