Page tree
Skip to end of metadata
Go to start of metadata

Last updated: Mar 07, 2018 13:56

By Raj Pasupathy 

Selenium grid lets you tests your scripts on different desktop browsers in parallel.

Selenium Grid Server Configuration Setup 
Selenium grid lets you tests your scripts on different desktop browsers in parallel. 

Download the latest required Selenium Server Standalone jar: http://www.seleniumhq.org/download/

Download the latest Firefox/Chrome/IE & Safari Drivers: http://www.seleniumhq.org/download/

/* Selenium HUB */
The hub is the main console that all the nodes will be connecting too. Therefore onces the HUB is started, firefox, IE & Chrome nodes can be connected to the main hub. See below diagram to start the selenium Admin Hub. Note: Please run cmd as an administrator. 

/* Specific Port Assign */ 
java -jar selenium-server-standalone-2.48.2.jar -port XXXX -role hub 

/* Default Port 4444 */ 
java -jar selenium-server-standalone-2.48.2.jar -role hub 

                                                                                               

                                                                                                Starting Hub Node

Admin Console View
Shows the users of all the running nodes against the HUB. Initially there will be no firefox, IE or chrome nodes listed on the admin console view. See sections below on how to start these nodes appropriately. 

Console View URL: http://localhost:4444/grid/console

                                                                                                 

                                                                                                 Admin Console View

                                                                                                 Shows all browser nodes attached to the Hub.


 

Connecting all Nodes to the HUB
Once the Admin hub is setup successfully, we can setup the individual nodes for IE, Chrome, Firefox & Safari respectively. My recommendation would be to setup each browser node independently. The reason being is that if one node goes down, it doesn’t bring the other node’s down. Note: the below hub starts a maximum instance of 10 browsers each. Please set the appropriate instance based on your hardware.

 

Setup all drivers with a single Node
A way to setup a single node connecting to a HUB.

IE, Chrome, Safari & firefox selenium NODE
java -Dwebdriver.ie.driver=C:/eclipse/IEDriverServer/IEDriverServer.exe -Dwebdriver.chrome.driver=C:/eclipse/chromedriver/chromedriver.exe -jar selenium-server-standalone-2.48.2.jar -port 5555 -role node -hub http://localhost:4444/grid/register -browser "browserName=firefox, maxInstances=10, platform=ANY, seleniumProtocol=WebDriver" -browser "browserName=internet explorer, version=11, platform=WINDOWS, maxInstances=10" -browser "browserName=chrome,version=ANY,maxInstances=10,platform=WINDOWS"

 

IE Node Setup
java -Dwebdriver.ie.driver=C:/eclipse/IEDriverServer/IEDriverServer.exe -jar selenium-server-standalone-2.48.2.jar -port 5555 -role node -hub http://localhost:4444/grid/register -browser "browserName=internet explorer,version=11,platform=WINDOWS,maxInstances=10"

 

Chrome Node Setup
java -Dwebdriver.chrome.driver=C:/eclipse/chromedriver/chromedriver.exe -jar selenium-server-standalone-2.48.2.jar -port 5556 -role node -hub http://localhost:4444/grid/register -browser "browserName=chrome, version=ANY, maxInstances=10, platform=WINDOWS" 

FireFox Node Setup
java -jar selenium-server-standalone-2.48.2.jar -port 5557 -role node -hub http://localhost:4444/grid/register -browser "browserName=firefox, maxInstances=10, platform=ANY, seleniumProtocol=WebDriver"

 

                                                                                                       

                                                                                                       All node Setup


Selenium Grid Server Code Access
The below java code snippet shows how to connect to all the nodes as all you need to do is provide the ip address of the VM where the node are configured. 

 

String ipAddress = "XXX.XXX.XXX.XX";
/* Firefox */
driver = new RemoteWebDriver(new URL("http://"+ipAddress+":4444/wd/hub"), capability);
/* Chrome */
driver = new RemoteWebDriver(new URL("http://"+ipAddress+":4444/wd/hub"), capability);
/* IE */
driver = new RemoteWebDriver(new URL("http://"+ipAddress+":4444/wd/hub"), capability);


/* Code Snippet */
try {
  if (context.getCurrentXmlTest().getParameter("browser").equals("firefox")) {  
        DesiredCapabilities capability = DesiredCapabilities.firefox();  
        driver = new RemoteWebDriver(new URL("http://"+ipAddress+":4444/wd/hub"), capability);    
        driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
     } else if (context.getCurrentXmlTest().getParameter("browser").equals("chrome")){
        DesiredCapabilities capability = DesiredCapabilities.chrome();
        driver = new RemoteWebDriver(new URL("http://"+ipAddress+":4444/wd/hub"), capability);    
        driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS);
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 
     } else if (context.getCurrentXmlTest().getParameter("browser").equals("IE")) { 
        DesiredCapabilities capability = DesiredCapabilities.internetExplorer();
        driver = new RemoteWebDriver(new URL("http://"+ipAddress+":4444/wd/hub"), capability);  
        driver.manage().timeouts().pageLoadTimeout(30, TimeUnit.SECONDS); 
        driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS); 
     }  else {                       
        System.out.println("Not able to set Driver object");                
        }      
 } catch (Exception e) {  
    e.printStackTrace();              
 }