To understand Selenium Grid you first need to understand how the standard Selenium web testing tool works.
To understand Selenium Grid you first need to understand how the standard Selenium web testing tool works.
Fundamentally, Selenium is a tool that let you programmatically launch a browser, drive the browser (open a url, enter some data, click on a link) and check the browser state (a section is visible, specific text is present, a widget is disabled). It is the tool of choice for automating web testing.
You drive the key piece in charge of controlling the browser, the Selenium Remote Control, by sending HTTP requests following a specific protocol (called Selenese). Therefore, basically all that a Selenium test does, is to target a specific Selenium Remote Control and to send it HTTP requests (through a higher level client API).
This setup works great for a few tests, but as your test suite starts getting bigger, its limitations become clearer:
Due to all these limitations, Selenium tests typically run in sequence or are only mildly parallelized. That makes for test suites that take from half an hour to multiple hours to run. Not ideal, especially if you strive for Agile processes emphasizing a quick feedback loop.
Selenium Grid builds on the traditional Selenium setup, taking advantage of the following properties:
Consequently, if only we could build a distributed grid of Selenium Remote Controls, we could easily share it across builds, applications, projects - even potentially across organizations. Of course we would also need to address the scalability issues as described earlier when covering the traditional Selenium setup. This is why we need a component in charge of:
Selenium Grid calls this component the Selenium Hub.
Of course to really take advantage of the Selenium Grid, you need to run your tests in parallel. If you are writing your Selenium tests in Java, you can leverage TestNG parallel runs or Parallel JUnit. If you prefer to write your Selenium tests in Ruby, you might want to look into DeepTest or spawn multiple processes. Chances are that your favorite programming language and development platform already have a solution.
A traditional Selenium test requests a specific browser at the beginning
of every Selenium session. It requests it in the form of a pre-defined
string such as *firefox or *iexplore.
Nevertheless a test cannot request more fine grained capabilities such
as Firefox on Linux or IE 6.0 on Windows XP SP2. The underlying
assumption is that you are targeting a single Remote Control, so you
should be aware if it runs on Windows XP or not.
If you want, you can operate a Selenium Grid in the exact same way. It might very well be all that you need. However the more heterogeneous your grid becomes, the more you will want to make sure that a specific build runs on Firefox on Windows and only on Firefox on Windows. This makes troubleshooting test failures considerably easier. It might also be that you have a handful of tests that are specifically targeting this nasty bug for this particular browser on this particular platform.
Either way, you can make a Selenium Grid aware of the environments you care about. The Selenium Hub will then ensure that a test runs only on the Selenium Remote Controls providing the requested environment.
The way it works is that Selenium Grid instruments the traditional Selenium Remote Controls so that they register themselves to the Hub when they start. When they do so they can also describe which environment they are providing, suppose Firefox on Windows.
At this point, if you want to target a test to a specific environment,
all you have to do is to substitute the traditional browser string (say
*firefox) with the name of the environment (say
Firefox on Windows). If you write your test in Java change:
new DefaultSelenium("localhost", 4444, **'*firefox'**, 'http://amazon.com');
into:
new DefaultSelenium("localhost", 4444, **'Firefox on Windows'**, 'http://amazon.com');
That will do the trick.
It is important to note that the names of the environments are completely arbitrary. You are in control and can choose the ones that make sense for you. You are also not restricted to the browser / platform paradigm. You can define environments such as “IE 7 on Chinese locale” or “Firefox on Quadri-processor” if that makes sense in your testing environment.
To define you own environments, edit the
grid_configuration.yml file at the root of the Selenium Grid
binary distribution.