Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] how to run playwright script in docker #2972

Closed
zammew opened this issue Jul 16, 2020 · 2 comments
Closed

[Question] how to run playwright script in docker #2972

zammew opened this issue Jul 16, 2020 · 2 comments

Comments

@zammew
Copy link

zammew commented Jul 16, 2020

I am still new to Docker so I am wondering how to execute the simplest playwright JS with node as the dockerfile provided in https://github.com/microsoft/playwright/blob/master/docs/docker/Dockerfile.bionic does not npm install playwright globally.

I ran this script:
const playwright = require('playwright'); (async () => { for (const browserType of ['chromium', 'firefox', 'webkit']) { const browser = await playwright[browserType].launch({headless: true, args: ['--no-sandbox']}); const context = await browser.newContext(); const page = await context.newPage(); await page.goto('http://whatsmyuseragent.org/'); await page.screenshot({ path: example-${browserType}.png}); await browser.close(); } })();
but I get error Error: Cannot find module 'playwright'

Any help is much appreciated fellow coders.

@yury-s
Copy link
Member

yury-s commented Jul 16, 2020

As you pointed out the Docker image does not include Playwright itself, so you'll have to install it separately, e.g. when running the Docker container you can do something like this:

npm init -y
npm install playwright --save

And then run your script from the same directory.

Alternatively you could bake Playwright into your docker image, e.g. by adding the following line to Docker.bionic:

RUN mkdir -p /home/pwuser/example && cd /home/pwuser/example && npm init -y && install playwright --save

@zammew
Copy link
Author

zammew commented Jul 16, 2020

thanks Yury. I got it working.

@zammew zammew closed this as completed Jul 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants