How to run multiple browsers on one hub using Selenium Grid2
I'm running a test:
DesiredCapabilities capability = DesiredCapabilities.Firefox();
IWebDriver dri开发者_开发百科ver = new RemoteWebDriver(new Uri("http://localhost:4444/wd/hub"), capability);
ISelenium selenium = new WebDriverBackedSelenium(driver, "http://localhost/");
selenium.Start();
This runs the Firefox browser, and in the http://localhost:4444/grid/console
web console view I can see that one Firefox browser is running. How can I use more than one browser on the node in parallel?
I'm using the Grid2 wiki page found here
You need to trigger 5 tests simultaneously - all pointing to the same hub, to use all the browsers. On receiving the commands from different tests, hub would pass those commands to RCs matching the capability. You can see more details in this page : http://selenium-grid.seleniumhq.org/how_it_works.html.
Per this site:-
Of course to really take advantage of the Selenium Grid, you need to run your tests in parallel. If you are writing your Selenium tests in Java, you can leverage TestNG parallel runs or Parallel JUnit. If you prefer to write your Selenium tests in Ruby, you might want to look into DeepTest or spawn multiple processes. Chances are that your favorite programming language and development platform already have a solution.
EDIT: The above given site was for Selenium 1.x version and not for Grid 2.0. However, the underlying concept for running parallel tests remains the same
EDIT2: Steps and example programs are below. Please note that this is a very basic test ONLY to show you how Grid runs tests in parallel.
Step1 - Start Grid Hub
java -jar selenium-server-standalone.jar -role hub
Step2 - Start RC nodes. The tests which we are using for example are webdriver tests. So we need to start webdriver nodes. This command would start a webdriver node which supports 5 firefox browsers, 5 googlechrome and 1 IE browser. This is the default config for webdriver.
java -jar selenium-server-standalone.jar -role wd -hub http://localhost:4444/grid/register
Step 3- Create 5 separate programs similar to the one given below. This program is in JAVA. You need to change it to the language you need. Change class name to Program2,Program3 etc. As mentioned earlier, this is not the best way to run tests in parallel. You need to use testNG or jUnit to trigger multiple tests at the same time. Since that is a different topic by itself am not going to explain it here.
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();
}
}
Step 4 - Run all 5 programs simultaneously.
Step 5 - Watch the grid doing the magic of running 5 tests in parallel. :)
精彩评论