Cross Browser Testing using Selenium Grid
What is cross browser testing ?
It is a type of functional testing where you need to test your web application works across multiple browsers such as chrome, Firefox, Internet Explore/Edge, Safari ...etc.
Why we need it ?
User can open the web application in any browser, and when user opens it in any browser your application should have to work/behave properly, same across the all browser.
Usually happens that web application works fine on chrome/Firefox but did't work on IE. Or works fine on IE and Chrome but not working on Firefox. As every browser has its own rendering engine.
What is selenium grid ?
Selenium grid is a tool/library(part of selenium suite) which allows you too run your test in different browser as well as on different environment/OS. Also it supports distributed test/scripts execution.
It is used to speed-up your test execution by spreading test on multiple machines to run tests parallel.
What is hub and node ?
- Hub is a machine or instance where you redirect your test.
- Node is a instance/client which will execute test that you have redirected to hub.
- You can launch hub and node on single machine.
- You can have a multiple node connected to the single hub.
- But you can not have a multiple hub i.e it should have only single hub.
- We can setup hub on windows , and connect node from Linux, Mac or any of the different platform. or vice versa. i.e there is no same system/os require to setup grid. as shown in above diagram.
Setup selenium grid hub and node :
Download selenium standalone jar from seleniumhq.org or click here.
1. Go to the folder where you have stored downloaded jar file.
2. cd webdriver (I have stored it on my home/webdriver)
3. Execute the following command to start your hub.
3.1 java -jar selenium-server-standalone-2.53.1.jar -role hub
3.2 It will start your hub by default on port no 4444, you can check it by hitting localhost:4444/grid/console in your browser. it will not show any details/browser as we have't registered any node to hub.
3.2 Also if you want to run hub on specific port just add -port port_no at the end of command
e.g. java -jar selenium-<your version>.jar -role hub -port 4123.
4. Open a new terminal/Command prompt and Register node by executing following command.
4.1 java -jar selenium-server-standalone-2.53.1.jar -role node -hub http://your_ip:4444/grid/register (you can use localhost instead of IP if your registering node from the same machine)
if you hit localhost:4444/grid/console in browser it will show like below
4.2 Above command will registered node using by default port no 5555.
if you wants to change it just user -port port_no parameter at the end.
e.g java -jar selenium-server-standalone-2.53.1.jar -role node -port 5152 -hub http://your_ip:4444/grid/register
4.3 It will register all available browser to hub,but its not a good way.
4.4 You can register a specific browser to the hub using -browser parameter.
e.g.
Java -jar selenium-server-standalone-2.53.1.jar -role node -hub http://your_ip:4444/grid/register -browser "browserName=chrome,version=50,platform=Linux" -Dwebdriver.chrome.driver="chromedriver" -browser "browserName=firefox,vesion=47,platform=Linux" -Dwebdriver.gecko.driver="geckoriver"
On Windows machine use chromedriver.exe and geckodriver.exe.
If you register node in above way it will show like below
Now you can use your script/modify your script to run using selenium grid by parameterizing test (junit/testng for java).
Let me know if you face any issue while setup, will happy to reply.