Wednesday 21 February 2018

How to setup parallel execution in selenium webdriver

Parallel execution in automation testing is very important and useful for fast execution. We can do with help of selenium grid.
I will walk you through how to setup parallel execution in selenium webdriver.

First of all we have to start Hub.

Please open command prompt and navigate to directory where you have stored all selenium jar files.
type below command and press enter

java -jar selenium-server-standalone-2.53.1.jar -role hub -port 4444

Once you press enter below message should be displayed.




now we have to start node and regiter that node on Hub

Please open another command prompt and navigate to directory where you have stored all selenium jar files.
type below command and press enter

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

Once you press enter below message should be displayed.




The node is registered to the hub and ready to use

Now you all set to run parallel execution.

If you want to run execution on other than Firefox than you have to start Node with below command. Hub is same for all browser

For Chrome :

java -jar selenium-server-standalone-2.53.1.jar -role hub -port 4444 -browser browserName=chrome -Dwebdriver.chrome.driver=path of chrome driver

For IE:

java -jar selenium-server-standalone-2.53.1.jar -role hub -port 4444 -browser browserName=iexplore -Dwebdriver.ie.driver=path of ie driver


Now you have to initiate driver.

For Firefox

DesiredCapabilities capability = DesiredCapabilities.firefox();

capability.setBrowserName("firefox");

Webdriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),capability);

For Chrome

System.setProperty("webdriver.chrome.driver","path of chrome driver");

DesiredCapabilities capability = DesiredCapabilities.chrome();
capability.setBrowserName("chrome");

Webdriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),capability);

For IE

System.setProperty("webdriver.ie.driver","path of iedriver");

DesiredCapabilities capability = DesiredCapabilities.internetExplorer();
capability.setBrowserName("internet explorer");

Webdriver driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"),capability);


1 comment:

Popular