Thursday 19 September 2013

Selenium Grid Installations

Download Required

1) selenium-server-standalone-ver.jar : All client machines and Server Machine


Steps :

Step 1 : Start the hub : Start hub on the Server machine with below command

java -jar selenium-server-standalone-2.28.0.jar -role hub

The hub will automatically start-up using port 4444 by default. To change the default port, you can add the optional parameter -port when you run the command. You can view the status of the hub by opening a browser window and navigating to: http://localhost:4444/grid/console

Step 2: Start the nodes : Regardless on whether you want to run a grid with new WebDriver functionality, or a grid with Selenium 1 RC functionality, or both at the same time, you use the same selenium-server-standalone jar file to start the nodes.

java -jar selenium-server-standalone-2.14.0.jar -role node  -hub http://localhost:4444/grid/register

-browser  browserName=firefox,version=3.6,maxInstances=5,platform=LINUX : This can be supplied .
For Windows : platform=WINDOWS
Note: The port defaults to 5555 if not specified whenever the "-role" option is provided and is not hub.

Using grid to run tests

 For WebDriver nodes, you will need to use the RemoteWebDriver and the DesiredCapabilities object to define which browser, version and platform you wish to use. Create the target browser capabilities you want to run the tests against:

 

DesiredCapabilities capability = DesiredCapabilities.firefox();

 

Pass that into the RemoteWebDriver object:
WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
The hub will then assign the test to a matching node.
A node matches if all the requested capabilities are met. To request specific capabilities on the grid, specify them before passing it into the WebDriver object.
capability.setBrowserName();
capability.setPlatform();
capability.setVersion()
capability.setCapability(,);
Example: A node registered with the setting:
 -browser  browserName=firefox,version=3.6,platform=LINUX
will be a match for:
capability.setBrowserName(“firefox ); 
capability.setPlatform(“LINUX”);  
capability.setVersion(“3.6”);
and would also be a match for
capability.setBrowserName(“firefox ); 
capability.setVersion(“3.6”);

Code Snippet : 

import java.net.MalformedURLException;
import java.net.URL;


import org.openqa.selenium.WebDriver;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.remote.RemoteWebDriver;
import org.testng.annotations.Test;


public class testremote {

    @Test
    public void test1() throws MalformedURLException{
  
    DesiredCapabilities capability = DesiredCapabilities.firefox();
    capability.setBrowserName("firefox");
    capability.setVersion("18.0.2");
    WebDriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), capability);
    driver.get("http://google.com");
  
  
}
  
}

 

No comments:

Post a Comment