SeleniumDocker Showcase

Softvisioner Sorin Veres Shares His First-Hand Tips

Run Selenium (C#) tests in a dockerized environment

Docker allows applications to run in an isolated environment with limited resources. Perhaps this is one of the reasons that made Docker so popular.

Codeship says: “The real area where Docker disrupts is in resource efficiency.” There are many tools used for virtualization but they need a lot of resources if you want to create an isolated environment.

Let’s say that you want to create 10 virtual machines. To boot this you need 10 operating systems with minimum requirements (CPU, Memory, HDD). You have to do the same settings for each VM. With Docker, you can allocate resources for a single VM and you can have a single operating system that will manage everything.

If you are interested in learning more about Docker vs. VM benchmarks, you can find more details here.

What is Infrastructure as Code?

Infrastructure as Code, or IaC, refers to the “practice of scripting the provisioning of hardware and operating system requirements concurrently with the development of the application itself.” (Source:

With the latest version of Selenium and .NET Core, you can create a framework that is platform independent. In this short article, we will create from scratch a project using .NET Core with Selenium C# and Docker.

We will create a dockerized environment for Selenium hub (2 nodes Firefox / Chrome + hub) and another container for our solution.

Because there is no official support for .NET Core in the current release of Selenium some changes were required. More details here.

What I changed in the WebDriver DLL: and I had to re-build the solution on my local machine. Now I’m able to use Selenium Remote WebDriver with .NET Core and I can create the environment.

We will have two docker-compose files. The first one will create the .NET Core container. The second docker-compose file will create:

  • Chrome node
  • Firefox node
  • Selenium hub


Content of docker-compose.selenium.yml:

Build the containers using:

To verify that the containers are running:

In Visual Studio create a new  XUnit Test Project (.NET Core). As I said earlier this project uses custom WebDriver DLLs. You will have to reference WebDriver and WebDriver.Support DLLs that were compiled earlier.

Test scenario:

  • Go to
  • Verify that the search box is enabled
  • Verify that the Search button is enabled
  • Search for “test”

Here is the code:

Fact code screenshot

To start execution I’m using the following shell script:

Binbash code

Save the script as: “”. Here is my project folder structure:

Content of docker-compose.netcore.yml:

version 3

Build the container using:

Using VNC Viewer you can connect to your container to verify that the test is started.

To remove the container you can run:


Don’t forget that this feature is not officially supported. Using Docker containers will allow you to run tests on all platforms: Linux, Windows and  Mac OS. In this example C# was used but this is compatible with all languages supported by Selenium libabry (Java, Ruby, Python, JavaScript – Node). You can also enable test parallelization to reduce execution time. For Internet Explorer and Microsoft EDGE there is no support but you can use Vagrant images. If you want to use BDD for your test framework you are limited to some basic frameworks like Light BDD. Specflow doesn’t have support for .NET Core – more details here. The environment setup is easier than ever, the *.yml file contains all definitions and you can control which step to be executed. It’s easy to integrate with your CI environment and is platform independent.