Rayrun
← Back to Discord Forum

Viewing report in docker

I have a docker image

Dockerfile

# Get the base image of Node version 16
FROM node:16

# Get the latest version of Playwright
FROM mcr.microsoft.com/playwright:focal
 
# Set the work directory for the application
WORKDIR /app
 
# Set the environment path to node_modules/.bin
ENV PATH /app/node_modules/.bin:$PATH

COPY .. /app/

# Get the needed libraries to run Playwright
RUN apt-get update && apt-get -y install libnss3 libatk-bridge2.0-0 libdrm-dev libxkbcommon-dev libgbm-dev libasound-dev libatspi2.0-0 libxshmfence-dev

# Install the dependencies in Node environment
RUN npm install
CMD [ "npx", "playwright", "test", "--reporter=list" ]

I am not able to view the report generated after running the tests . i tried running npx playwright show-report from CL in vscode and from the container in docker desktop. No luck viewing the report. Any help would be great

image.png

This thread is trying to answer question "How can I view the report generated after running tests in a Docker container?"

7 replies

also tried this docker run -it playwright-docker-2:latest npx playwright show-report

Wouldn’t you need to be line connected and on the actual container to do that second part?

I see what you mean, like run the command when In the container and can see the directory

Lemme try that

tried from the shell

image.png

Viewing report in docker is not straightforward, you basically need some vnc. It would be better to mount tests in docker and after running the tests launch report from host.

alejandrorey
alejandrorey

Show report needs a browser with a graphical interface, in Docker you don't have this. I recommend you to use better npx playwright show-trace trace.zip. And defining a local volume.

Answer

Accessing Playwright Test Reports in Docker

First, ensure Playwright is installed in your Docker container. You can include the installation commands in your Dockerfile or run them manually inside the container.

Next, run your tests inside the Docker container. Use the command npx playwright test followed by the path to your test files. Don't forget to include any necessary flags or options for running tests in headless mode or with specific browsers.

npx playwright test /path/to/your/test/files

After running the tests, Playwright generates an HTML report with detailed test results. To access this report, extract it from the Docker container and open it in a web browser.

To extract the HTML report from the Docker container, you can:

  • Navigate to the directory on your host machine where you've mounted a volume or bind mount for storing artifacts generated during testing. Locate the HTML report file there.
  • Or, if no volume or bind mount was used, copy the HTML report file from within the Docker container to your host machine using the docker cp command.
docker cp containerId:/path/to/report.html /host/path/to/report.html

Once you have the HTML report file on your host machine, serve it using a local web server. You can do this within a folder where Playwright is installed.

Change into the directory where you extracted the HTML report file and use npx playwright show-report followed by the name (or path) of the report.

cd /path/to/report
npx playwright show-report report.html

This starts a local web server that serves up the report. Now you can view your test results in detail!

Related Discord Threads

TwitterGitHubLinkedIn
AboutQuestionsDiscord ForumBrowser ExtensionTagsQA Jobs

Rayrun is a community for QA engineers. I am constantly looking for new ways to add value to people learning Playwright and other browser automation frameworks. If you have feedback, email [email protected].