A little background
Recently at the office the team I am assigned to have been tasked with build a quick start tool chain for a project. This got me thinking, how easy could I start up a Selenium Grid to test a web application using some of my favorite tools? As I am also a large supporter of testing something in my brain said ‘yep, do this’. So herein is how to use the project I put together using Docker, AWS, Selenium, and Terraform.
Part 1: Local Setup
Before anything else please ensure the prerequisites are configured and functioning properly. Specifically the AWS CLI and Terraform. These two tools are core and must be functional locally. (Check with the vendor for setup instructions if needed.)
Once the configuration values are added initialize the Terraform configuration.
If everything goes as expected we should be returned to the terminal prompt with a successfully initialized Terraform project. With that completed let’s go ahead and stand up the infrastructure.
Part 2: Setting up Selenium Grid Service
The project has two main parts. A Selenium Grid host and a Web App host. The next step will be to setup the Selenium Grid host. Lucky for us the Selenium team provides a basic
docker-compose.yml. I took this and rolled it into the
./resources/selenium.sh script. Ideally a software config tool would be used to transfer the config to the remote host but eh, I didn’t feel like it. Anyways, each of the two hosts have two setup steps: copy the script via SCP; then execute the script by passing the command via SSH.
If you are familiar with docker-compose the last few lines should look familiar to you as well. What we see here is the docker-compose.yml being processed and the services being started. As this point we have a fully functional Death Sta…er… Selenium Grid. If we visit the public DNS of the machine the Selenium Grid (as provided from the terraform apply output) the web console should load. (NOTE: Selenium Grid is NOT secure. It has NO access controls nor authentication. Security should be setup in front of any public Grids.)
Part 3: Setting up Web App Service
Now that the Grid is up and running time to start up the Web App. For this project I used the Java Spring Boot Pet Clinic web app. It seemed a logical choice since 1) many people are familiar with it and 2) writing a Selenium test case was similar to other tools I have used in the past. So lets get it going here.
Unlike the Selenium setup this takes a bit longer due to the web app needing to compile and start up. After a some moments though visiting the public DNS should result in the Pet Clinic app loading in the browser.
Nice! Everything is up and running. So far, so good.
Part 4: Execute!
With everything up and running the only thing left is to trigger the Selenium browser test. Here is where things get a bit confusing. The test case/s logic is executed on the Web App instance (not a good idea in production systems) and connects to the Selenium Grid’s hub instance. The Hub service receives the test request capabilities and routes it to an appropriate browser node. In our case Chrome on Linux. The execution command is a bit long in the tooth but it does not require use to hard any values manually. This is important for automation when integrating the tools into a CI / CD pipeline.
Boom, goes the dynamite! A successfully executed browser test.
Step 5: Taking it all down
Like all good things this to must end. Since this is all put together with Terraform it can be taken down even more quickly than it took to start up. Excellent for temporary environment or proof of concepts.
Bonus: Request / Response Diagram
Hope you found this as informative to read as it was for me to put it together. It shows just how flexible and capable automation tools can be to get things up and running as well as manageable with minimal of effort.
- GitHub Repository: https://github.com/davidjeddy/docker_aws_selenium_terraform