Monday, April 3, 2017

Testing on Multiple web browsers - Selenium Grid - C#

Most easiest way to create list of web browsers in a one single PC/Server is having a selenium GRID.

1. Download the selenium server from SeleniumHQ.
https://goo.gl/uTXEJ1

2. We need to execute the downloaded selenium server.
As it is a jar file we need to execute it via CMD.

3. Execute the jar file with below code.
java -jar selenium-server-standalone-3.3.1.jar -role hub

If the selenium grid working fine you have to get this INFO on your CMD.
INFO - Selenium Grid hub is up and running

4. Two double check it ,Navigate to http://localhost:4444/grid/console.
You should see something like this.



5. Then we have to add Web browsers to this grid.
If we add chrome driver by default it will give us  5 Chrome, 5 Firefox and 1 IE browser under Browser section like below.
Below is how we add the chrome driver in order to get 11 default web browsers.

java -Dwebdriver.chrome.driver=chromedriver.exe -jar selenium-server-standalone-3.3.1.jar -role node -hub http://localhost:4444/grid/register

highlighted EXE should be replace with the EXE file path to the latest chrome web driver which you can download from Selenium HQ.

2nd highlighted are is the URL where we have already host our Selenium grid.


6. If you wont any other browsers then navigate to Selenium HQ and download any browser's WEB DRIVER.
Then execute the below code.

java -Dwebdriver.chrome.driver=chromedriver.exe -jar selenium-server-standalone-3.3.1.jar -port 5556 -role node -hub http://localhost:4444/grid/register -browser "browserName=chrome, version=ANY, maxInstances=10, platform=WINDOWS

First line you need to mention the exact driver name and the driver EXE name.
Then the jar file name where we use to create the selenium GRID at the beginning.

7. Then again navigate to http://localhost:4444/grid/console. 

8. You should see 10 chrome icons at the Selenium grid server.
We called it as Chrome instances.




9. Now the Grid is up and ruining,Just access the browsers at the Grid by below code.

 Uri hub = new Uri("http://localhost:4444/wd/hub");
 DesiredCapabilities capabilities = DesiredCapabilities.Chrome(); <You can change the driver to IE or FireFox.>
 IWebDriver driver2 = new RemoteWebDriver(hub, capabilities);

 driver2.Navigate().GoToUrl("http://www.yahoo.com");



No comments:

Post a Comment