Monday, 16 December 2013

Detailed steps to implement selenium grid

1.Down load selenium standlone jar file from https://code.google.com/p/selenium/downloads/list 
 2.Then copy the jar file in any folder.ex c://SeleniumGridEx.
3.Go to that folder using command prompt.
4.Then type this command java -jar selenium-server-standalone-2.xx.xx.jar -role hub--it will act like central for all nodes
5.Any other system you want to be as a node then copy the same jar file in to other systems.
6.Then move to that folder using command prompt for node system and type below command.
 java -jar selenium-server-standalone-2.xx.xx.jar -role node  -hub http://<Ipaddress of hub system>:4444/grid/register
7.Now type this URL http://localhost:4444 in hub system able to see the grid console.

To run script on node system see the below example code.

public class GoogleEx {
     WebDriver driver;
 
    DesiredCapabilities capability;
 @Before
 public void beforeClass(){
      capability= new DesiredCapabilities();
   capability.setCapability("takesScreenshot", true);
    capability.setBrowserName("chrome");
   }
 @Test
 public void search() {
     try{   
         driver= new RemoteWebDriver(new URL("http://<Ipaddress of node  system>:5555/wd/hub"), capability);
   then go on with script.
               

            }catch(Exception e){
                e.printStackTrace();
            }            

  }

 @After
 public void afterClass(){
     driver.quit();
  }
  }


No comments:

Post a Comment