Python, Selenium Grid and Docker

With Docker you can quickly and easily install, configure and use Selenium Grid. This tutorial shows the respective steps that you need as a software tester (or Developer). Instead of Python you can also use other languages, which are supported by Selenium​.


Preparation of files

Note: You can opt for a version of docker-compose.yml!

Version: 1

Version: 2

Create environment

Open Browser

Selenium Grid Console

Run Python script

Note: Via browserName ( you can choose the respective browser (firefox or chrome)!

Note: Via docker-compose scale you can add/remove node instances!

Create screenshot with Python Selenium Webdriver

The following example show how easy you could make screenshots with Python Selenium Webdriver.



The could be used on different places.

After running the test you should see the folder “/screenshot” with the picture.

JUnit report with Python Webdriver

To create JUnit reports, you just need the python library xmlrunner. This is needed for the integration with build server like Jenkins.



Just replace for example:



On Jenkins add a new “post-build” action and select the Publish JUnit test result report. Add now the string “reports/*.xml” into the “Test report XMLs” field.

DDT with Python Selenium

DDT (Data-driven Testing) with Python Selenium Webdriver is very easy! DDT becomes very useful if you have test cases that contains the same test steps. All values could outsourced into files or databases. This tutorial use CSV files.


  • Python installed
  • selenium and ddt library installed


The folder structure for this tutorial looks like:

Into folder “data” we store the csv files. The packages “library” include a function to read the specific csv files and the package “scenarios” include the test cases. The test suite is on root folder.

Into the “” we add all test cases provided by scenario package.

data folder

The CSV stores the test data that we supplied to the @data decorator of test case.

library package

Just for read the csv and return the values as a list.

scenarios package

Test case with @ddt (for classes), @data and @unpack (for methods) decorators.

  • @data take the arguments from csv file
  • @unpack unpacks tuples or lists into multiple arguments

The test_search() method accepts the arguments, which will be mapped to the tuple values by ddt.


Python, Selenium and PhantomJS – ignore certificate errors


You are done with your work and push all into Git. The Build-Server starts his work and all test scripts are failing. Short look and it is clear – certificate errors. The next example shows, how to ignore certificate errors on PhantomJS.

Now it should work….

HAR with Python WebDriver and BrowserMob Proxy

This time is shown how to automate performance test for web sites. Tools in usage are Python Selenium WebDriver and BrowserMob proxy. The results are HAR files which can be viewed in HAR Viewer.


  • JAVA installed
  • Python Packages for selenium and browsermob-proxy


Download BrowserMob Proxy and check if proxy can started by command-line.

Create Python Class

Note: The highlighted line must contain the path to BrowserMob Proxy!
Happy testing! If you use PhantomJS instead of Firefox, you can use this on Build server like Jenkins/Hudson and so on, too.

Run your Python Selenium tests headless

This time i show you the headless testing with Selenium WebDriver and PhantomJS. This method can be used for example on continuous integration systems.

Install PhantomJS

Follow the documentation on PhantomJS website or as Mac OS X user simply use Mac Ports.

Create a tiny test script

Just create a instance of PhantomJS WebDriver and run you tests. That is all! 😉

Start with Python and Selenium WebDriver

This introduction should give you some hints about Python and Selenium WebDriver. I will use this in following tutorials as a base.


  • Python installed
  • pip (package manager) installed
  • Editor or IDE installed


As first step simply install or upgrade the Selenium package.

This is a fairly simple process. After the successful command execution you will have the Selenium WebDriver client library on your machine with all that is needed to create automated scripts.

The first script

Now start using the unittest library. The script comments help to describe the code.

Run Test

To run the test simple call your script.