Selenium Grid:what should be the remotewebDriver URL to run in multiple machines

742 views
Skip to first unread message

sunil patro

unread,
Apr 19, 2016, 8:00:34 AM4/19/16
to Selenium Users
Hello Experts,

I have a  sample code to run across 2 nodes, I m confusing if I need to keep the below line as it is or change needed:

driver = new RemoteWebDriver(new URL("http://10.112.70.32:9500/wd/hub"), cap); //Hub ip address with hub port


Please help me if I can write the line "driver = new RemoteWebDriver(new URL("http://10.112.70.32:9500/wd/hub"), cap);" to run my selenium tests in both the node machines?

pranab singh

unread,
Apr 19, 2016, 8:32:25 AM4/19/16
to seleniu...@googlegroups.com

Hi sunil, to run in multiple machine you need to have a switch statement or some conditions,stating that if it's Firefox then use this node else some other node.
The node url should differ from one other based on machine add also the parameter like chrome, Firefox etc

--
You received this message because you are subscribed to the Google Groups "Selenium Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to selenium-user...@googlegroups.com.
To post to this group, send email to seleniu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/selenium-users/6ae51845-60c9-4f81-9c24-d5c6bb4fe60e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

sunil patro

unread,
Apr 19, 2016, 8:48:45 AM4/19/16
to Selenium Users
I m fine with the switch statement to select particular browsers in node machines, the only confusion for each of the tests run in different nodes, do I need to change the remotewebdriver URL in code or just I can keep the hub URL for all the node machine runs....

Here is my code:
public class Grid {
static WebDriver driver = null;
static String br = null;
@Parameters({"browser", "remoteurl"})
@Test
public static void openGoogle(String browser, String remoteurl) throws InterruptedException, IOException
{
br=browser.toString();
DesiredCapabilities cap = new DesiredCapabilities();
switch (browser)
{
case "firefox":
    cap = DesiredCapabilities.firefox();
    //cap.setBrowserName("firefox");
    break;
case "ie":
File file = new File("c:\\Grid\\IEDriverServer.exe");
System.setProperty("webdriver.ie.driver", file.getAbsolutePath());
    cap = DesiredCapabilities.internetExplorer();
    //cap.setBrowserName("internet explorer");
  //cap.setBrowserName("iexplorer");
    break;
case "chrome":
System.setProperty("webdriver.chrome.driver","c:\\Grid\\chromedriver.exe");
ChromeOptions options = new ChromeOptions();
options.addArguments("--start-maximized");
options.addArguments("test-type");
       //driver = new ChromeDriver(options);
    cap.setCapability(ChromeOptions.CAPABILITY, options);
    cap = DesiredCapabilities.chrome();
    //cap.setBrowserName("chrome");
    break;
default:
    cap = DesiredCapabilities.firefox();
    //cap.setBrowserName("firefox");
    break;
}
cap.setPlatform(Platform.WINDOWS);
                //hub ip address
//driver = new RemoteWebDriver(new URL("http://10.112.70.32:9500/wd/hub"), cap);
//Node Machine IP address
driver = new RemoteWebDriver(new URL(remoteurl+"/wd/hub"), cap);
driver.manage().timeouts().implicitlyWait(4, TimeUnit.SECONDS);
//driver.manage().window().maximize();
Thread.sleep(2000);
driver.navigate().to("http://www.gmail.com");
}
}

and My testng.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Grid" parallel="tests" thread-count="3">
<test name="Test1">
      <parameter name="browser" value="firefox" />
      <parameter name="remoteurl" value="http://10.112.70.32:5551" />
      <classes>
          <class name="hubnode.Grid" />
      </classes>
</test>
<test name="Test2">
      <parameter name="browser" value="chrome" />
      <parameter name="remoteurl" value="http://10.112.70.32:5551" />
      <classes>
          <class name="hubnode.Grid" />
      </classes>
</test>
<test name="Test3">
      <parameter name="browser" value="ie" />
      <parameter name="remoteurl" value="http://10.223.204.105:5552" />
      <classes>
          <class name="hubnode.Grid" />
      </classes>
</test>
</suite>

But I do not want to pass the remote url through testng.xml as parameter, are there any alternative to this?

pranab singh

unread,
Apr 19, 2016, 11:27:30 AM4/19/16
to seleniu...@googlegroups.com

Hi sunil if u don't want to pass parameter from. xml file then remove the remoteurl patameter from openGoogle method.And add ->


driver = new RemoteWebDriver(new URL(remoteurl+"/wd/hub"), cap);

with the correct remote url(ie the individual node based on browser) and include it inside the switch case for individual browser..
Eg..for Firefox:::


switch (browser)
{
case "firefox":
    cap = DesiredCapabilities.firefox();

    cap.setBrowserName("firefox");
driver = new RemoteWebDriver(new URL(NODE FOR FIREFOX+"/wd/hub"), cap);

You can use it this way.

As you will have node specific to browser,  use independently the particular node url for particular browser..

Regards
Pranab Chetri

⇜Krishnan Mahadevan⇝

unread,
Apr 19, 2016, 10:23:40 PM4/19/16
to Selenium Users
Sunil,

Can you please help us understand why you are specifically looking for having your test run in both the nodes ? What does it solve ?
Distribution of tests to the nodes is something that the Hub takes care of. If you are going to resort to doing that by yourself, then you might as well just kick off a bunch of selenium standalones, do away with the grid and have your test point to both of the individual standalones and run tests no ? why would you need the grid ?

In simple terms in order for your tests to be executed in all nodes, all you would do is the following :

1. Use the latest version of Grid [ this is because the session allocation logic of the hub has changed in the recent versions and I dont remember the exact version from which the change has been introduced ]
2. Spin off your nodes.
3. Create two or more threads of your tests and have them pointed at your Hub.

The hub now resorts to taking into considering the usage information of every node when it comes to allocating sessions apart from the usual capability match.

So for the second test, it would basically route your test to the second node since when compared to the first node [ which already is running your first test ] the second node is comparatively less loaded.

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

Ram Narayan

unread,
Apr 20, 2016, 2:54:52 AM4/20/16
to Selenium Users
Hi Sunil,
As per your requirement which i understood id below two points...

1. You want to run the test cases in two systems in parallel using selenium grid.
2. You don't want to pass the IP addresses from the testNG.xml file.

Solution:

In the testbase.java(where you create the RemoteWebDriver Instance) file of your testing framework.

i. Declare a String for the ip address'.say,  String ipaddress = (read from the text file).

Ex: 

String ipaddress1 = genMethods.getTestDataValueFromPropertiesFile("IPAddress3");  
  runOnIPnBrowser(ipaddress1,browser); (calling the method with the node/ipaddress and the browser you want to run in...)

ii. Create a method to set the drivercapabilities with the ipaddress a a parameter 

Ex : 

private void runOnIPnBrowser(String ipaddress, String browser) throws MalformedURLException {
// TODO Auto-generated method stub
switch(browser.toLowerCase())
{
case "chrome":
System.out.println("Entered in to chrome");
DesiredCapabilities capabilitychrome = DesiredCapabilities.chrome();
capabilitychrome.setBrowserName("chrome");
capabilitychrome.setPlatform(Platform.WIN8_1);
    this.driver= new RemoteWebDriver(new URL(ipadress),capabilitychrome);
break;
case "firefox":
System.out.println("Entered in to FF");
DesiredCapabilities capabilityff = DesiredCapabilities.firefox();
capabilityff.setBrowserName("firefox");
capabilityff.setPlatform(Platform.WIN8_1);
this.driver= new RemoteWebDriver(new URL(ipadress),capabilityff);
break;
case "internet explorer":
System.out.println("Entered in to IE");
DesiredCapabilities capabilityie = DesiredCapabilities.internetExplorer();
capabilityie.setBrowserName("iexplore");
capabilityie.setPlatform(Platform.WIN8_1);
this.driver= new RemoteWebDriver(new URL(ipadress),capabilityie);
break;
}
}
Reply all
Reply to author
Forward
0 new messages