如何使用Selenium Grid2在一个集线器上运行多个浏览器

我正在进行测试:

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维基页面

您需要同时触发5个测试 – 所有测试都指向同一个集线器,以使用所有浏览器。 在接收来自不同测试的命令时,集线器会将这些命令传递给与该function匹配的RC。 您可以在此页面中查看更多详细信息: http : //selenium-grid.seleniumhq.org/how_it_works.html 。

根据这个网站: –

当然要真正利用Selenium Grid,您需要并行运行测试。 如果您使用Java编写Selenium测试,则可以使用TestNG并行运行或Parallel JUnit。 如果您更喜欢在Ruby中编写Selenium测试,则可能需要查看DeepTest或生成多个进程。 您最喜欢的编程语言和开发平台已经有了解决方案。

编辑:上面给出的网站是Selenium 1.x版本,而不是Grid 2.0。 但是,运行并行测试的基本概念仍然相同

EDIT2:步骤和示例程序如下。 请注意,这是一个非常基本的测试,仅用于向您展示Grid如何并行运行测试。

步骤1 – 启动Grid Hub java -jar selenium-server-standalone.jar -role hub

第2步 – 启动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个测试的魔力。 🙂