我正在进行测试:
DesiredCapabilities capability = DesiredCapabilities.Firefox();
IWebDriver driver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), capability);
ISelenium selenium = new WebDriverBackedSelenium(driver, "http://localhost/");
selenium.Start();
这将运行Firefox浏览器,在http://localhost:4444/grid/console
Web控制台视图中,我可以看到一个Firefox浏览器正在运行。如何在节点上并行使用多个浏览器?
我正在使用Grid2 wiki页面found here
答案 0 :(得分:8)
您需要同时触发5个测试 - 所有测试都指向同一个集线器,以使用所有浏览器。在接收来自不同测试的命令时,集线器会将这些命令传递给与该功能匹配的RC。您可以在此页面中查看更多详细信息:http://selenium-grid.seleniumhq.org/how_it_works.html。
根据这个网站: -
当然要真正利用Selenium Grid,你需要 并行运行测试。如果你正在写你的Selenium测试 Java,您可以利用TestNG并行运行或Parallel JUnit。如果你 我更喜欢用Ruby编写你的Selenium测试 进入DeepTest或产生多个进程。有可能是你的 最喜欢的编程语言和开发平台已经有了 溶液
编辑: 上面给出的站点是Selenium 1.x版本而不是Grid 2.0。但是,运行并行测试的基本概念仍然相同
EDIT2: 步骤和示例程序如下。请注意,这是一个非常基本的测试,仅用于向您展示Grid如何并行运行测试。
第1步 - 启动网格中心
java -jar selenium-server-standalone.jar -role hub
Step2 - 启动RC节点。我们使用的测试例如是webdriver测试。所以我们需要启动webdriver节点。此命令将启动一个webdriver节点,该节点支持5个firefox浏览器,5个googlechrome和1个IE浏览器。这是webdriver的默认配置。
java -jar selenium-server-standalone.jar -role wd -hub http://localhost:4444/grid/register
步骤3-创建5个与下面给出的程序类似的单独程序。此程序在JAVA中。您需要将其更改为您需要的语言。将类名更改为Program2,Program3等。如前所述,这不是并行运行测试的最佳方法。您需要使用testNG或jUnit同时触发多个测试。由于这是一个不同的主题本身我不打算在这里解释。
public class Program1{
public static void main(String args[]){
WebDriver wd;
//Assign a remotewebdriver object to webdriver with firefox capability
wd=new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),DesiredCapabilities.firefox());
wd.get("http://www.google.com");
//Sleep for 2 seconds so that RC will not be released. This is to demonstrate Hub using multiple RCs
Thread.sleep(120000);
//Close webdriver
wd.quit();
}
}
第4步 - 同时运行所有5个程序。
步骤5 - 观察网格并行执行5个测试的魔力。 :)强>