I am trying to run my playwright tests with the Docker container, but unfortunately the dependency "@playwright/test" is missing.
This is the command I use: docker run --rm -v $(pwd)/tests:/tests -w /tests mcr.microsoft.com/playwright:focal npx playwright test
In the first step, I simply want to run the example test from the tutorial "First test": https://playwright.dev/docs/writing-tests
But I get the following error:
Error: Cannot find module '@playwright/test' Require stack:
1 | import { test, expect } from '@playwright/test'; | ^ 2 | test('has title', async ({ page }) => { 3 | await page.goto('https://playwright.dev/'); 4 | // Expect a title "to contain" a substring. at Object.<anonymous> (/tests/example.test.js:1:1) Error: No tests found
What am I doing wrong?
This thread is trying to answer question "Why do I need to install the '@playwright/test' dependency in a Docker container that is specifically meant for Playwright?"
Usually test projects have some dependencies of their own. And when executing tests, you typically will mount a volume in the Docker container with that project, having a package.json, the project source files, the installed node_modules folder, etc.
If the Docker container would contain those things, in many cases it wouldn't be used because you would mount your own project over it.
That feels wrong. Why should I install playwright within a playwright-container?
For that to work the container should include all package managers and their “node_modules” equivalent which will make image bloated and even bigger than it is now. And you would still need to npm/etc install to install your own test deps.
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].