Rayrun
← Back to Discord Forum

Missing dependencies in Docker container?

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:

  • /tests/example.test.js
  • /root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/lib/transform/transform.js
  • /root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/lib/common/config.js
  • /root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/lib/reporters/json.js
  • /root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/lib/reporters/html.js
  • /root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/lib/runner/reporters.js
  • /root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/lib/runner/runner.js
  • /root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/lib/cli.js
  • /root/.npm/_npx/e41f203b7505f1fb/node_modules/playwright/cli.js at example.test.js:1

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?"

7 replies

You need npm install it

That feels wrong. Why should I install playwright within a playwright-container?

If so I will issue a bug report / feature request. Why would one create a Docker container without the necessary testing dependencies? 🤔

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.

Okay, one could do that. But in which cases should an end2end test depend on source code? I expect my system test to click through a website and perform some assertions.

With source code, I meant source code of the end to end tests.

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.

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 luc@ray.run.