Up arrow

Using Docker to simplify and improve testing with Selenium

Contents

  1. Selenium and ChromeDriver
  2. Docker
    -> Docker Overview -> Working with containers -> Volumes -> Working with images -> Dockerfiles -> Dockerizing a Web App
  3. Docker Networking
    Creating a network -> Adding containers to a network
  4. Selenium Grid
    Standalone Mode -> Start a grid on Standalone mode -> Running a simple test -> Grid with Hub and Nodes

Contents

  1. Docker Compose
    Starting a Selenium Grid via Docker Compose -> Stopping the containers -> Docker Compose Project Name -> Docker Compose commands -> How do we add the Ruby container to the Docker Compose file? -> Waiting for the container -> Configuration Options and Scenarios -> Scaling up a Selenium Grid to run tests in parallel
  2. Continuous Integration

Everything you need

- PDF presentation

- Workshop Video 1 (05:13:37)

- Workshop Video 2 (02:20:40)

- Confluence Documentation

Setup and Requirements

Down arrow

Docker Installed

Docker Images

Please pull the following Docker images (by executing the commands shown below):


                    docker pull ubuntu:18.04
                    docker pull nginx
                    docker pull node:10
                    docker pull selenium/node-chrome-debug
                    docker pull selenium/node-firefox-debug
                    docker pull selenium/hub
                    docker pull maven:3.6.1-jdk-8
                    docker pull ruby:2.6.3
                

Others

A good text editor (Code, Eclipse or IntelliJ), and a GitHub account

1. Selenium and ChromeDriver

We will learn:

- What is Selenium
- Selenium WebDriver Flow
- To use ChromeDriver to navigate and search for an element (Exercise).

We will need:

- ChromeDriver installed

Down arrow

Quick overview

Selenium automates browsers. Describes the user interaction with a web application, emulates what a user would do.

WebDriver is just an API.

ChromeDriver is an open source tool and provides capabilities for navigating to web pages, user input, JavaScript execution, and more.

2. Docker

2.1. Docker Overview

We will learn:

- What is Docker
- Why do we use containers

Down arrow

Quick overview

Docker is a tool designed to make it easier to create, deploy, and run applications by using containers.

A container is a standardized unit of software.

What happens in the container does not affect the host.

The names of the containers are generated with a random pronoun and a random name.

2.2. Working with containers

We will learn:

- Running a container
- Running a container in the background
- Stopping a container
- Useful Docker commands

2.3. Volumes

We will learn:

- Volumes advantages
- Creating a Volume (Exercise)

We will need:

- carousel.html

Down arrow

Quick overview

Volumes are used for sharing.

- Sharing a directory between multiple containers.

- Sharing a directory between the host and a container.

- Sharing a single file between the host and a container.

2.4. Working with Images

We will learn:

- What is an Image
- Useful Image commands
- Building an Image manually and tagging it (Exercise)

Down arrow

Quick overview

Images are like templates.

An image is the union of files and metadata

There are two ways of creating an image: Manual and Automated (preferred one - Dockerfiles)

2.5. Dockerfiles

We will learn:

- What is a Dockerfile
- Creating a Dockerfile and building an image (Exercise)
- Caching builds
- Tips for good Dockerfiles

Down arrow

Quick overview

A Dockerfile is a set of instructions to build a Docker image.

It tells Docker how an image is constructed.

2.5. Dockerizing a Web App

We will learn:

- Dockerizing a Web App with a basic Dockerfile (Exercise)

We will need:

- sample-node-app.zip

3. Docker Networking

We will learn:

- Creating a network (Exercise)
- Adding containers to a network (Exercise)

4. Selenium Grid

We will learn:

- Why Selenium Grid
- Start a grid on Standalone mode (Exercise)
- Running a simple test (Exercise)
- Grid with Hub and Nodes (Exercise)

We will need:

- VNC Viewer
- sample-node-app.zip

Down arrow

Quick overview

Selenium Grid allows you run your tests on different machines against different browsers in parallel.

A grid consists of a single hub, and one or more nodes.

Selenium Hub is the intermediary. Take instructions from the client and executes them remotely on nodes.

Selenium Node does not evaluate, make judgments, or control anything: it only receives and executes instructions (and throws exceptions).

Down arrow

Quick overview

To a start a Grid in Standalone Mode we need to have Java installed.

This is how people were doing it some years ago when Docker wasn’t that popular. This is not the ideal workaround.

To reduce the amount of work -> Docker containers. Problem: it is not easy to provide containers for IE or Safari -> Open Source projects (Docker container, Selenoid, Zalenium).

The main requirement to have a grid with a hub and nodes is that all of them are connected and able to communicate.

5. Docker Compose

We will learn:

- What is Docker Compose
- Starting a Selenium Grid via Docker Compose (Exercise)

We will need:

- sample-node-app.zip

Down arrow

Quick overview

Docker Compose is a tool for defining and running multi-container Docker applications.

With Docker Compose you use a YAML file to configure your application’s services. Then, with a single command, you create and start all the services from your configuration.

Docker Compose is great to avoid having many manual terminal commands to start all our containers.

Docker Compose puts all the running containers in the same network

If Starting a Selenium Grid via Docker compose fails it could because the hub was not completely up and nodes try to register in something that is not running. It will be solved in next exercise.

5. Docker Compose

We will learn:

- Stopping the containers
- Docker Compose Project Name
- Docker Compose commands
- Docker Compose Build (Exercise)
- How do we add the Ruby container to the Docker Compose file? (Exercise)

We will need:

- sample-node-app.zip

Down arrow

Quick overview

With Docker Compose Build we will build and image from a Dockerfile.

We will add the Ruby Container to the composer file in order to run a test.

With this approach, the test will fail because the hub is not ready, the container is started but the service is not up and ready to receive connections.

5. Docker Compose

We will learn:

- Waiting for the container (Exercise)
- Configuration Options and Scenarios
- Scaling up a Selenium Grid to run tests in parallel (Exercise)

We will need:

- sample-node-app.zip
- sample-node-app__environment.zip
- link-follower.zip

6. Continuous Integration

We will learn:

- Creating a GitHub repository with Travis integration.

We will need:

- GitHub Account
- sample-node-app__ci.zip

THANKS FOR YOUR TIME!