How to use Selenium Grid
In one of my previous position we were running our tests multi browser using SOUCELABS services. The problem that we had it was with the connection , it was ridiculously slow and I started to investigate how to use selenium grid propertly. Well it wasn’t entirely souce labs fault we had a lot of proxy servers and network filters due to the security policy from the company.
But this was affecting our test execution time very bad so we were thinking to build our grid infrastructure in house.
It was a painful process , to build business cases to convince the business what benefits will bring that on and after to deal with the infrastructure team to get everything as a package not just machines that can run selenium grid.
Overview of the infrastructure:
We started with one hub and 40 nodes all machines were linux machines.
The hub configuration was , I7 CPU , 32 gb ram , SSD and gigabit ethernet, and each node was I7 , 16gb ram, SSD , and gigabit ethernet.
After we started to give it a try we figured out that we need to fix some issues to have it more reliable, so we decided to have some extra tools in top of the grid:
A Selenium Grid Extras Primer
Some of the benefits that can bring with are :
Explicitly kill web browser after each test
As you all know from different reasons during the execution there might be leftovers with browser instances that are hanging around, so Extras Primer will help us to to kill any remaining or crashed instances of the browser used.
Restart Grid Nodes from time to time
Selenium grid is a quite powerful tool but it still has some memory leaks , we found that restarting the Java process from time to time is the fastest and most reliable.
Restart the operating system after several runs
We found out that after 15-25 sessions of test executions is good to restart the machines and gave us a huge stability.
Having in place all these setup and cleanups we were able to run somewhere at 45000 test sessions in one month, with only 2.5% failure rate due to node instability.
java -jar selenium-server-standalone.jar -role hub 12:04:25.542 INFO - Launching Selenium Grid hub
Register a node:
java -jar selenium-server-standalone.jar -role node -hub http://localhost:4444/grid/register 12:05:32.776 INFO - Launching a Selenium Grid node
Be aware that will only demonstrate a single node , if you want to setup multiple machines , you’ll need to place the selenium standalone server across each machine.
You can view the gird console up and running navigating to http://localhost:4444/grid/console.
Capybara cucumber code setup
You can see a full list of the available Selenium
Capabilities options here.
Bellow you can find out the configuration for each browser: