skip to Main Content

I am trying to deploy my playwright automation framework in a docker container. However I assume that the browser won’t launch (don’t have any logs).

When I run my tests locally in VS code, they look like this:
Playwright Local Execution

When I run my tests in Docker container, they look like this:
Docker execution

It is clear that it is missing the [Google Chrome] or [chromium] at the beginning of the line. I assume that the browser is not getting launched.

My dockerfile looks like this:

# playwright:bionic has everything to run playwright (node, npm, chromium, dependencies)
#FROM mcr.microsoft.com/playwright:bionic
#COPY .. .
FROM node:14
FROM mcr.microsoft.com/playwright:focal
WORKDIR /app
ENV PATH /app/node_modules/.bin:$PATH
COPY package*.json /app/
#COPY features/ /app/features/
COPY src/ /app/src/
#COPY cucumber.js /app/
#COPY tsconfig.json /app/
#COPY reports/ /app/reports/
COPY *.config.json /app/
RUN npm install
RUN npx playwright install
CMD npm run test
#ENTRYPOINT ["npm run test"]

Any ideas how to get the tests to run in a container?

3

Answers


  1. Chosen as BEST ANSWER

    This problem was fixed by adding:

    FROM mcr.microsoft.com/playwright:bionic
    

    which added all the needed dependencies.


  2. If not using the mcr.microsoft.com/playwright:bionic with all the dependencies, add this line after the RUN npx playwright install to get the browser binaries:

    COPY  /root/.cache/ms-playwright/ /root/.cache/ms-playwright/
    
    Login or Signup to reply.
  3. You can start from the provided image mcr.microsoft.com/playwright:v1.16.2-focal:

    FROM mcr.microsoft.com/playwright:v1.16.2-focal
    # copy project files
    COPY . /e2e
    
    WORKDIR /e2e
    
    # Install dependencies
    RUN npm install
    RUN npx playwright install
    
    # Run playwright test
    CMD [ "npx", "playwright", "test", "--reporter=list" ]
    

    The --reporter=list option is to print a line for each test being executed.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search