Py.Saunter 0.48 – Selenium Grid, Parallel Execution and CI
With the release of Py.Saunter 0.48 there is support for running your scripts in parallel, and against a Selenium grid.
So how would you do this with Py.Saunter? Well, of course, there are many different ways. But what is my ‘official’ way of doing this. Crazy enough, that’s what this post is about.
-
Setup Se Grid – Starting small, you should create a single node grid. Starting full-scale is going to drive you insane. For this, you need to have a hub and a node instance of the Se Server. For my play instance, I did it all on the same machine. But yes, you still need to have two instances of the server running on the same machine. Both the hub and the node can take a boatload of commandline arguments, but I like to use the json config file instead since that is easier to manage through Puppet or similar.
The Grid2 wiki page is actually quite good describing all this. For our purposes now, constrain it to a single browser.
- Get a single script working – The really nice part about the new Se Grid is that your script does not change whether it is going directly against a Se Server or against a hub; the executor location is the same. ```
[Selenium] server_host: localhost server_port: 4444 ``` does not change for a single node.
- Add another node – Add another node, with a different browser specified in the node config. Run your script. It should execute through the other node.
-
Filter – We’re now at the point where we want to filter nodes. Py.Saunter is designed to execute only one browser and one platform combination at a time. The rationale for this is primarily ease of debugging and for ease of observation of results. We filter at this level rather than have a whole bunch of Grids; this way we can have just a single grid in our organization but lots of jobs in our CI (see below…). To filter which platform and/or browser version you use the new Grid section of in the saunter.ini.
<pre lang="shell">[Grid] use_grid: true type: selenium platform: mac browser_version: 13.0.1
- Add your grid to CI – I use the Traffic Cop / Job / Vandal pattern for integration things into CI. For now, just create two distinct browser jobs. The first Py.Saunter job should fail, since you have not checked in your saunter.ini files… but after you have created a local saunter.ini and made the necessary customizations things should be green. (Or blue if you are using Jenkins…)
- Parallelization – Right now the scripts are executing through CI, but in a synchronous manner. And that can be rather slow. The trick is to run them in parallel. Your speed then is limited entirely to how many nodes are in your grid (or how many parallel jobs you are allowed to have at Sauce Labs). In your CI job configuration, add -n # to the job command where # is the number of nodes that could fulfill the task.
And now you have your Py.Saunter…
- running in parallel
- in ci
- giving very specific quality information on a per-browser basis