Web Automation Test Solutions with Docker, Selenium and Cucumber.js

Ted Cheng
Ted Cheng
Aug 25, 2017 · 5 min read

Objective: build a feasible web automation testing solutions that lower the learning curve of the whole setting up and coding.

Selenium Grid

Selenium helps you communicate and get elements from browsers. It receives HTTP requests and responses with the data you need. You can foresee that every programming language, that is able to send HTTP request, can communicate with Selenium

A Selenium grid consists of hubs and nodes. Hubs distribute works to nodes. Nodes receive orders and communicate with browsers. Obviously, it’s an architecture that you can do the scaling out easily.

node.js

Javascript is now a widely used language. AngularJS, ReactJS and node.js. And it’s easy to learn. That’s why I would like to use this.

Cucumber.js

Cucumber is a BDD test framework. You code test cases here. The most important advantage of it is the human readable syntax. Non-programmers can easily contribute to the code base.

Docker

Docker is now the famous tool that help setting up systems. With the help of DockerHub, lots of systems can be easily constructed by a few commands. This is the key part of the solution.

Situations

There are three situations (or problems to solve). Different solutions make us of different setups. They can be compared in the views of difficulty and scalability.

Quick Development

It’s the case that we are most likely to face. We have lots of QAs that know nothing about server setup. They just know some basic programming skills.

Our concerns:

  1. installing libraries and servers is a difficult task
  2. installing tools is kind of making your computer “dirty”
  3. too many ways to install tools. there may be lots of differences among them.

my expect outcome:

  1. QAs do not need to install too much tools, except docker and git.
  2. QAs can use their own text editors to code
  3. QAs don’t need to handle any server config
  4. QAs can just destroy and recreate the system easily when facing weird issues

my solution:

  1. QAs download code by git
  2. QAs install docker
  3. Developers config the whole docker-compose file. Actually, for Selenium Grid, you can easily copy the whole setting from internet.
  4. QAs run ‘docker-compose up’ to start the whole selenium grid
  5. the ‘docker-compose up’ will also start a node.js container to run javascript
  6. with docker’s volume mounting, QAs can just edit code in the host computer.
  7. with docker’s volume mounting, QAs don’t need to download application’s related packages. They all are installed inside the docker container.
  8. QAs edit code in the host, and run test command inside the container.
  9. DONE!

Problems left:

  1. DockerHub doesn’t have the selenium-safari image. Safari cannot be tested.
  2. As the browsers are inside the docker containers, you can’t see the browser running. ( Yet, when you literally start writing code, you won’t spend time on the browsers)

Deep-dive debugging

It’s the case that we will face the least. There should be cases that we really need to see the browser running (though I don’t even meet this situation, logically we need to plan it also). It’s exactly the opposite of the previous solution. I won’t spend too much time on this.

Our concerns:

  1. sometime we need to find out how steps being run

my solution:

  1. install the whole stack, git, node, selenium, all browsers…
  2. do coding and run commands in the host computer

Problem left:

  1. a lots… just the opposite of the previous solution

Regression test

Other than developing test cases, we always need to do regression tests before deploying.

Our concerns:

  1. Regression test should involve Safari.
  2. the host should be powerful enough to run these huge amounts of test cases as fast as possible

my solution:

  1. as the setup will be a bit more complicated, we better setup a server to handle this. QAs can start the regression test by send HTTP request from their computer. Deployment tools, like Jenkins, can also run test on it.
  2. using Docker compose to build a selenium grid like the quick-development solution.
  3. also install one more selenium in the host. this selenium will handle all the Safari testing.

Whole Picture

To conclude, we can setup two regression test servers. One for Production, one for Development and QA environment. Based on the developer’s skill level, they can use the ‘Quick Development’ or ‘Deep-dive Debugging’ aproaches.

The remaining part !

The remaining part is the Cucumber layer. It’s a huge topic. I am still figuring it out. I have built a framework to some basic application management. Feel free to check this out:

It mainly handle the config massaging and page-object concept. Go and take a look of the README.md

)

Ted Cheng

Written by

Ted Cheng

Simply an engineer working in a Hong Kong Startup. Having lots of crazy “philosophies” behind my work.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade