[Automation Testing] Use Docker or Docker Compose to run Playwright to test Web applications automatically

col-playwright-docker

col-playwright-docker is a Docker image to use Fast and reliable end-to-end testing for modern web apps | Playwright - https://playwright.dev/ to test Web applications automatically.

Prerequisites

  • Docker - https://www.docker.com/

    Developing apps today requires so much more than writing code. Multiple languages, frameworks, architectures, and discontinuous interfaces between tools for each lifecycle stage creates enormous complexity.

    Docker simplifies and accelerates your workflow, while giving developers the freedom to innovate with their choice of tools, application stacks, and deployment environments for each project.

    To learn more about all the features of Docker, see Docker - https://www.docker.com/

  • Docker Compose - https://docs.docker.com/compose/

    Docker Compose is a tool for defining and running multi-container Docker applications. With 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.

    To learn more about all the features of Docker Compose, see Docker Compose - https://docs.docker.com/compose/.

Usage

1
2
3
4
5
6
$ git clone https://github.com/CloudoLife/col-playwright-docker.git

$ cd col-playwright-docker

$ docker build
# Or run docker-compose build

Docker

Edit or modify ./Dockerfile with your preferred content.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# Docker | Playwright
# https://playwright.dev/docs/docker
# ARG IMAGE=mcr.microsoft.com/playwright:bionic
ARG IMAGE=mcr.microsoft.com/playwright:focal

FROM ${IMAGE}

ARG WORK_DIR="/app"
RUN mkdir -p ${WORK_DIR}

WORKDIR ${WORK_DIR}
COPY . ${WORK_DIR}

RUN npm i -D playwright

Run with docker command.

1
2
3
$ docker build .

$ docker run -it -v $PWD:/app --rm --name col-playwright-docker col-playwright-docker bash

Docker Compose

Edit or modify [./docker-compose.yml] with your preferred content.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# docker-compose.yml

version: '3'

services:
# docker-compose run app bash
# docker-compose run --service-ports app bash
app:
build:
context: .
image: col-playwright-docker
# ports:
# - 3000:3000
# environment:
# - FLAG_debug_print=true

volumes:
- "./:/app"

Run with docker-compose command.

1
$ docker-compose run app bash

References

[1] CloudoLife/col-playwright-docker: col-playwright-docker - https://github.com/CloudoLife/col-playwright-docker

[2] cloudolife/col-playwright - https://hub.docker.com/r/cloudolife/col-playwright

[3] Fast and reliable end-to-end testing for modern web apps | Playwright - https://playwright.dev/

[4] Docker - https://www.docker.com/

[5] Docker Compose - https://docs.docker.com/compose/