Selenium Grid Router is a lightweight server that routes and proxies Selenium Wedriver requests to multiple Selenium hubs.
There is a smaller and faster Golang implementation of this server. See https://github.com/aerokube/ggr for more details.
If you're frequently using Selenium for running your tests in browsers you may notice that a standard Selenium Grid installation has some faults that can prevent you from using it on large scale:
The basic idea is very simple:
Currently we maintain only Debian packages. To install on Ubuntu ensure that you have Java 8 installed:
# add-apt-repository ppa:webupd8team/java
# apt-get update
# apt-get install oracle-java8-installer
Then install Gridrouter itself:
# add-apt-repository ppa:yandex-qatools/gridrouter
# apt-get update
# apt-get install yandex-grid-router
# service yandex-grid-router start
Configuration files are located in /etc/grid-router/
directory, XML quota files - by default in /etc/grid-router/quota/
, log files reside in /var/log/grid-router/
, binaries are installed to /usr/share/grid-router
.
Two types of configuration files exist:
A typical file looks like this:
alice:alicePassword, user
bob:bobPassword, user
As you can see passwords are NOT encrypted. This is because we consider quotas as a way to easily limit Selenium browsers consumption and not a restrictive tool.
This file has the following format:
<qa:browsers xmlns:qa="urn:config.gridrouter.qatools.ru">
<browser name="firefox" defaultVersion="33.0">
<version number="33.0">
<region name="us-west">
<host name="my-firefox33-hub-1.example.com" port="4444" count="5"/>
</region>
<region name="us-east">
<host name="my-firefox33-hub-2.example.com" port="4444" count="5"/>
</region>
</version>
<version number="37.0">
<region name="us-west">
<host name="my-firefox37-hub-1.example.com" port="4444" count="3"/>
<host name="my-firefox37-hub-2.example.com" port="4444" count="4"/>
</region>
<region name="us-east">
<host name="my-firefox37-hub-3.example.com" port="4444" count="2"/>
</region>
</version>
</browser>
<browser name="chrome" defaultVersion="42.0">
<version number="42.0">
<region name="us-west">
<host name="my-chrome42-hub-1.example.com" port="4444" count="10"/>
</region>
<region name="us-east">
<host name="my-chrome42-hub-2.example.com" port="4444" count="10"/>
</region>
</version>
</browser>
</qa:browsers>
What we basically do in this file - we enumerate hub hosts, ports and counts of browsers available on each hub. We also distribute hosts across regions, i.e. we place hosts from different datacenters in different <region> tags. The most important thing is to make sure that browser name and browser version have exactly the same value as respective Selenium hub does.
Grid router is using BASIC HTTP authentication. That means that for the majority of test frameworks connection URL would be:
http://username:password@grid-router-host.example.com:4444/wd/hub
However some Javascript test frameworks have their own ways to specify connection URL, user name and password.
When you request a browser by specifying its name and version Grid Router does the following:
Our experience shows that Grid Router works better with a big set of "small" hubs (having no more than 5 connected nodes) than with some "big" hubs. A good idea is to launch small virtual machines (with 1 or 2 virtual CPUs) containing one Selenium hub process 4-5 Selenium node processes that connect to localhost. This gives us the following profit:
We're using Docker and Ansible for integration tests so you need to install them on your Mac or Linux.
brew install ansible
touch /usr/local/etc/ansible/hosts
echo 'localhost ansible_python_interpreter=/usr/local/bin/python' >> /usr/local/etc/ansible/hosts
pip install requests[security]
pip install -Iv https://pypi.python.org/packages/source/d/docker-py/docker-py-1.1.0.tar.gz
boot2docker up
boot2docker ip
/etc/hosts
: <boot2docker_ip> boot2docker
$(boot2docker shellinit)
export DOCKER_HOST=tcp://boot2docker:2376
mvn clean package
ansible-playbook testing/start.yml
docker ps -a
$ ansible-playbook testing/test.yml
$ ansible-playbook testing/stop.yml