Selenium Forum: Functional And Regression Testing Tool.
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
Display results as :
Advanced Search
Latest topics
AEM Training | Free Online DemoWed Apr 21, 2021 5:45 pmazharuddin
c# PageFactory - issue initializing elementsFri Nov 01, 2019 8:40 pmthegoatboy
Selenium making automatic connection to random urlsMon Jul 08, 2019 12:58 pmrepairtechsolutions1
How can we design the custom framework in Selenium RCMon Jun 24, 2019 2:26 pmrandybonnettes
What are the new features in Selenium 3.0Tue Jun 18, 2019 5:37 pmpappyvicky
What are you using Selenium for? Fri Apr 12, 2019 3:52 amzhl
LIMITATIONS OF SELENIUMWed Apr 10, 2019 11:23 amswara
Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Go down
Advisor
Advisor
------------------------
------------------------
Posts : 387
Join date : 2009-07-30
Location : India
https://seleniumforum.forumotion.net

GRID setup tutorial. Empty GRID setup tutorial.

Tue Mar 15, 2016 2:51 pm
Hi Guys,

I have done selenium grid setup on 5 different node which contains 2 LINUX and 3 Windows node. I would like to share the setup information to reduce the R&D time on that, which is totally frustrating Sad. But not any more, It's just a simple example of working setup and feel free to modify as per your requirement.

Pr-requisite:

  1. download selenium standalone server on hub machine and setup Java also on all machines.
  2. download all the browser drivers which you want to supported on node and placed in a common directory.
  3. All machine should be on same network group otherwise you will have to do some effort to resolve the network and firewall issues.


Hub setup:
java -jar selenium-server-standalone-2.52.0.jar -role hub -port 4441


Node's setup:
java -jar selenium-server-standalone-2.52.0.jar -role webdriver -browser browserName=chrome -browser browserName=firefox -browser browserName="internet explorer" -hub [You must be registered and logged in to see this link.] -port 5566 -Dwebdriver.ie.driver=C:\Users\Advisor\Downloads\Selenium_browser_Driver\IEDriverServer_x64_2.52.2\IEDriverServer.exe  -Dwebdriver.chrome.driver=C:\Users\Advisor\Downloads\Selenium_browser_Driver\chromedriver_win32\chromedriver.exe

Make sure all nodes are successfully registered and communicate properly with hub. Now, setup your IDE for working with web driver. google it if you don't know , how to setup.

This is the java code for running your test using grid. But right now it will execute on a single node at a time. If want to execute it on all setup node at the same time. You will have to use TestNG framework parallel method to execute simultaneously.

Code:


import net.sourceforge.htmlunit.corejs.javascript.ast.SwitchCase;

import org.openqa.selenium.By;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.ie.InternetExplorerDriver;
import  org.openqa.selenium.remote.DesiredCapabilities;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.Arrays;

import org.openqa.selenium.remote.RemoteWebDriver;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.Assert;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Test;

import com.gargoylesoftware.htmlunit.javascript.host.file.File;

/**
 *
 * @author adviser
 * grid command for node
 * java -jar selenium-server-standalone-2.52.0.jar -role webdriver -browser browserName=chrome -browser browserName=firefox -browser browserName="internet explorer" -hub http://152.144.219.191:4441/grid/register -port 5566 -Dwebdriver.ie.driver=C:\Users\Advisor\Downloads\Selenium_browser_Driver\IEDriverServer_x64_2.52.2\IEDriverServer.exe  -Dwebdriver.chrome.driver=C:\Users\Advisor\Downloads\Selenium_browser_Driver\chromedriver_win32\chromedriver.exe
 */



public class GridDriver {
 
 private static WebDriver driver;
 private static String baseURL,nodeURL;
 
 public GridDriver(String  nodeURL,DesiredCapabilities capability) throws MalformedURLException{
 // TODO Auto-generated constructor stub
 this.driver =  new RemoteWebDriver(new URL(nodeURL),capability);
 }
 
 public static void main (String[] ars) throws MalformedURLException, InterruptedException{
 
 baseURL = "http://google.com/";
 //nodeURL = "http://152.144.219.11:5566/wd/hub";
 
 //new GridDriver("http://152.144.219.64:5599/wd/hub", setBrowserAndPlatform(driver,"firefox", Platform.LINUX));
 new GridDriver("http://152.144.219.11:5566/wd/hub", setBrowserAndPlatform(driver,"chrome", Platform.WINDOWS));
        //new GridDriver("http://152.144.219.11:5566/wd/hub", setBrowserAndPlatform(driver,"internet explorer", Platform.WINDOWS));
 // new GridDriver(driver, "http://152.144.219.58:5577/wd/hub", setBrowserAndPlatform("firefox", Platform.XP));
 driver.get(baseURL);
 //driver.wait(50000);
 WebElement element = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.name("q")));
 Assert.assertEquals(driver.getTitle(),"Google");
 
 driver.quit();
 
 }
 
 private static DesiredCapabilities setBrowserAndPlatform(WebDriver driver,String browserName,Platform PlatformName){
 DesiredCapabilities capability = null;
 java.io.File file =null;
 String pathToIEdriver ="C:\\Selenium_browser_Driver\\IEDriverServer_x64_2.52.2\\IEDriverServer.exe";
 String pathToChromedriver ="C:\\Selenium_browser_Driver\\chromedriver_win32\\chromedriver.exe";
 switch (browserName) {
 case "firefox":
 capability= DesiredCapabilities.firefox();
 capability.setBrowserName(browserName);
 
 break;
 case "internet explorer":
 
 //java.io.File file = new java.io.File(pathToIEdriver);
 capability= DesiredCapabilities.internetExplorer();
 capability.setBrowserName(browserName);
 capability.setJavascriptEnabled(true);
 capability.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
 
 break;
 
 case "chrome":
 file = new java.io.File(pathToChromedriver);        
        System.setProperty("webdriver.chrome.driver", file.getAbsolutePath());
 capability = DesiredCapabilities.chrome();
 capability.setBrowserName("chrome");
 capability.setCapability("chrome.switches", Arrays.asList("--start-maximized"));
 
 break;
 default:
 break;
 }
 
 capability.setPlatform(PlatformName);
 return capability;
 }
}







Hope this will help for newbie Smile . Best of luck for GRID.
avatar
johnyapp
Posts : 1
Join date : 2017-09-27
Age : 35
Location : Hyderabad
https://tekslate.com/

GRID setup tutorial. Empty selenium grid setup

Wed Sep 27, 2017 4:29 pm
Hi,


In this section, you will use 2 machines. The first machine will be the system that will run the hub while the other machine will run a node. For simplicity, let us call the machine where the hub runs as "Machine A" while the machine where the node runs will be "Machine B." It is also important to note their IP addresses. Let us say that Machine A has an IP address of 192.168.1.3 while Machine B has an IP of 192.168.1.4.



Thank you @ Tekslate
Back to top
Permissions in this forum:
You cannot reply to topics in this forum