How to run multiple browsers on one hub using Selenium Grid2
Asked Answered
S

1

2

I'm running a test:

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();

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

Snodgrass answered 2/8, 2011 at 17:29 Comment(1)
Do you have 5 tests in your test suite?Neuter
N
8

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. :)

Neuter answered 2/8, 2011 at 19:38 Comment(4)
i still working with this. I always get errors and ff close when run it 2 times. If run it just once then works. Why? How then run it 2 times or more. Can you give me example? ThxSnodgrass
OK, I have updated my answer. Note that am not using WebDriverBackedSelenium object in example program. You can add that line to the code instead of using wd.getNeuter
i must tell you that now everything works like it must. WIth ws is much faster then with rc. Thx againSnodgrass
Cool. Glad that I could help you.Neuter

© 2022 - 2024 — McMap. All rights reserved.