SeleniumDocker Showcase

Softvisioner Sorin Veres Shares His First-Hand Tips

Sorin joined Softvision in 2010 and since then he gained expertise in UI & backend automation, performance testing and build automation. He is also interested in developing his leadership skills and sharing his knowledge, leading to his new role of QA Community Lead in 2017. In his spare time, Sorin is passionate about mountain biking, hardware and traveling.

Latest posts by Bogdan

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.

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.

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

Environment

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.

Content of docker-compose.netcore.yml:

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:

Conclusion

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.

Sorin joined Softvision in 2010 and since then he gained expertise in UI & backend automation, performance testing and build automation. He is also interested in developing his leadership skills and sharing his knowledge, leading to his new role of QA Community Lead in 2017. In his spare time, Sorin is passionate about mountain biking, hardware and traveling.