Project Release: Docker + AWS + Selenium + Terraform. Get it up and running.

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.)

05 - dast_0.png

Once the configuration values are added initialize the Terraform configuration.

05 - dast_0_1.png

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.

05 - dast_1.png
terraform plan and terraform apply commands with suggested arguments.
05 - dast_1_1.png
terraform plan resulting output.
05 - dast_1_2.png
terraform apply resulting output.

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.

05 - dast_2.png
The SCP and SSH command logic.
05 - dast_2_1.png
SCP copying the script onto the Selenium host.
05 - dast_2_2.png
The script execution ending.

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.)

Ignore the localhost address, this image is ‘borrowed’.

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.

05 - dast_3.png
Commands are very similar to setting up the Selenium Grid
05 - dast_3_1.png
Looks familiar…
05 - dast_3_2.png
Up and running, nice!

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.

Look at them cute animals! :cuteness:

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.

05 - dast_4.png
Passing the execution command via SSH to the Web App.
05 - dast_4_1.png

Boom, goes the dynamite! A successfully executed browser test.

Selenium is a massively feature and even take screen captures of each step executed; tests can be written in Java, Javascript, Python, and many other languages. Seriously, take a look at the docs.

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.

05 - dast_5.png
05 - dast_5_1.png

Bonus: Request / Response Diagram

Not to complicated when you see like this.

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.

Resources

Leave a Reply

Your email address will not be published. Required fields are marked *