Selenium is a well known and widely used open source framework which provides the power of browser automation. It can serve any purpose as far as browser automation is concerned, but it is mainly and very effectively been used in testing domain for test automation purposes.
Problem arises when you think of running your tests in distributed environment, which means you want to distribute your tests on several machines in parallel i.e. on different browsers / OS.
Which leads to the question; does Selenium itself supports running tests in distributed environment? Yes, it does with the help of Selenium-Grid.
Other part of the problem is; to prepare infrastructure to be able to run tests in distributed environment. For that sake, a number of (physical / virtual) machines with different OS and browsers are needed.
There are generally two approaches, as far as infrastructure for distributed environment is concerned; either you create your own distributed environment or use one of commercial solutions.
Let’s say creating own distributed environment is the option for now, which requires having several (physical / virtual) machines with different OS and browsers.
Apart from the (hardware, software & operational) cost itself, It’s a cumbersome job to prepare and maintain that sort of infrastructure.
Docker solves the problem, by making it possible to prepare the scaleable distributed environment on the go using containers, without even thinking about the hardware part of it.
Proof Of Concept:
Let’s try to prepare selenium-grid environment using docker containers, and run some UI tests on Storytel web using it, by following step-by-step approach.
Step 1: Prepare selenium-grid environment;
- Install docker on machine on which test scripts are going to run.
- Create a docker-compose file, and configure it to have a selenium-hub and two selenium-nodes, one with Chrome and one with Firefox.
- Create and run selenium-grid using docker-compose.
Step 2: Prepare selenium test scripts;
- Create a maven project and add following dependencies in pom file.
- Use the Page Object Model (POM) pattern to avoid the duplications and separate the page-objects and test-scripts logic. See https://github.com/Storytel/sthp-ui-automation as an example.
Step 3: Hook up everything in Jenkins CI;
- Create a Jenkins job and configure it with your code repo.
- Add a Build Step to start selenium-grid and run test scripts.
- Add a Post Build Task to stop and vanish selenium-grid.
- Add another Post Build Task to generate allure report.
- See test results for builds. Following are some screenshots of test results.
- Scale the grid with more OS and browsers.
- Add screenshots / videos in test reports (at least for failures)
- Kubernetes the tests, automation with docker on GCP.