microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
65.76k stars 3.58k forks source link

[BUG] Unable to run playwright scripts on Jenkins #12190

Closed gauravgandhi1315 closed 2 years ago

gauravgandhi1315 commented 2 years ago

Context:

const { test } = require('@playwright/test');
const { SimResults } = require('../selectors/simulationResults');
const playwright = require('playwright');

test.describe('Output Edit', () => {
  test('Simulations page', async ({ page }) => {
    for (const browserType of ['chromium', 'firefox', 'webkit']) {
      const browser = await playwright['chromium'].launch();
      const context = await browser.newContext();
      const page = await context.newPage();
      await page.goto('https://www.google.com');
      await page.click(SimResults.SimResultPage.simPage(2));
    }
  });
});

Describe the bug I have playwright_download_host=https://.../repository/playwright-raw-proxy in .npmrc file and downloading is working fine.

Jenkins error


14:44:58  + npm run test
14:44:59  
14:44:59  > playwright@1.0.0 test-galileo-chrome /jenkins/workspace/home-automation_main
14:44:59  
14:45:00  
14:45:00  Running 1 test using 1 worker
14:45:00  
14:45:07    ���  [chromium] ��� src/ui/specs/simulationPage.spec.js:6:3 ��� Output Edit ��� Simulations page (215ms)
14:45:10  
14:45:10  
14:45:10    1) [chromium] ��� src/ui/specs/simulationPage.spec.js:6:3 ��� Output Edit ��� Simulations page =
14:45:10  
14:45:10      browserType.launch: 
14:45:10      ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
14:45:10      ��� Host system is missing a few dependencies to run browsers. ���
14:45:10      ��� Please install them with the following command:            ���
14:45:10      ���                                                            ���
14:45:10      ���     sudo npx playwright install-deps                       ���
14:45:10      ���                                                            ���
14:45:10      ��� <3 Playwright Team                                         ��
'''
daddyman commented 2 years ago

This might be a duplicate of #12075. Firefox would not launch using the Docker image. It was fixed in 1.19.1.

The problem was that for Firefox there is now an extra dependency needed,

gauravgandhi1315 commented 2 years ago

@daddyman Im running on chromium and not using Docket image. Locally it runs fine on chromium but on Jenkins. it is not running and i see browserType.launch: without any error

daddyman commented 2 years ago

@gauravgandhi1315 If you use 1.19.1 does it fix it?

gauravgandhi1315 commented 2 years ago

Im using 1.19.0

gauravgandhi1315 commented 2 years ago

let me try with 1.19.1

gauravgandhi1315 commented 2 years ago

@daddyman Same error with 1.19.1

gauravgandhi1315 commented 2 years ago

I have tried to add executablePath as PLAYWRIGHT_BROWSERS_PATH=/jenkins/.cache/ms-playwright/*but getting this error

browserType.launch: Failed to launch: Error: spawn /jenkins/.cache/ms-playwright/ EACCES

dgozman commented 2 years ago

Your Jenkins machine is missing some dependencies. The error message has a suggestion of what you should add to your Jenkins pipeline before running Playwright:

Host system is missing a few dependencies to run browsers.
Please install them with the following command:

     sudo npx playwright install-deps

<3 Playwright Team
gauravgandhi1315 commented 2 years ago

@dgozman It doesn't say that anymore after I added executablePath look at the last comment

dgozman commented 2 years ago

Well, I guess there is nothing at that PLAYWRIGHT_BROWSERS_PATH location? I strongly suggest to let Playwright handle the browsers path itself, and just install the dependencies with sudo npx playwright install-deps.

gauravgandhi1315 commented 2 years ago

@daddyman Im running in enterprise jenkins and sudo npx playwright install-deps ask for password which I can't enter. Not sure how to handle it and Im using location of PLAYWRIGHT_BROWSERS_PATH where it was downloaded. Look below:

Playwright build of chromium v965416 downloaded to /jenkins/.cache/ms-playwright/chromium-965416 Playwright build of ffmpeg v1007 downloaded to /jenkins/.cache/ms-playwright/ffmpeg-1007 Playwright build of firefox v1316 downloaded to /jenkins/.cache/ms-playwright/firefox-1316 Playwright build of webkit v1609 downloaded to /jenkins/.cache/ms-playwright/webkit-1609

I have been stuck with this issue for very long time. I would really appreciate if you can help me.

dgozman commented 2 years ago

But the original issue is with dependencies, not with the actual browsers. Browsers on linux do not work without dependencies installed.

Try running npx playwright install-deps without a sudo - perhaps you don't need sudo on your Jenkins machine?

Alternatively, run npx playwright install-deps --dry-run. This will print the dependencies that are required for Playwright browsers to run. You can then add them to your Jenkins machine/image by any other means you prefer, instead of running install-deps command.

I hope this helps!

gauravgandhi1315 commented 2 years ago

@dgozman yes, originally I was getting npx playwright install-deps but then I added executablePath and Im seeing a different error now. Look below complete logs:

Running 1 test using 1 worker 17:58:26 17:58:27 ��� [chromium] ��� src/ui/specs/simulationPage.spec.js:5:3 ��� Output Edit ��� Simulations page (29ms) 17:58:31 17:58:31 17:58:31 1) [chromium] ��� src/ui/specs/simulationPage.spec.js:5:3 ��� Output Edit ��� Simulations page = 17:58:31 17:58:31 browserType.launch: Failed to launch: Error: spawn /jenkins/.cache/ms-playwright EACCES 17:58:31 =========================== logs =========================== 17:58:31 <launching> /jenkins/.cache/ms-playwright --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-breakpad --disable-client-side-phishing-detection --disable-component-extensions-with-background-pages --disable-default-apps --disable-dev-shm-usage --disable-extensions --disable-features=ImprovedCookieControls,LazyFrameLoading,GlobalMediaControls,DestroyProfileOnBrowserClose,MediaRouter,AcceptCHFrame,AutoExpandDetailsElement --allow-pre-commit-input --disable-hang-monitor --disable-ipc-flooding-protection --disable-popup-blocking --disable-prompt-on-repost --disable-renderer-backgrounding --disable-sync --force-color-profile=srgb --metrics-recording-only --no-first-run --enable-automation --password-store=basic --use-mock-keychain --no-service-autorun --export-tagged-pdf --headless --hide-scrollbars --mute-audio --blink-settings=primaryHoverType=2,availableHoverTypes=2,primaryPointerType=4,availablePointerTypes=4 --no-sandbox --user-data-dir=/tmp/playwright_chromiumdev_profile-GYvdXv --remote-debugging-pipe --no-startup-window 17:58:31 [pid=N/A] starting temporary directories cleanup 17:58:31 [pid=N/A] finished temporary directories cleanup 17:58:31 ============================================================ 17:58:31 17:58:31 at Object._baseTest.extend.browser.scope [as fn] (/jenkins/workspace/0006172_home_cei-automation_main/node_modules/@playwright/test/lib/index.js:163:51) 17:58:31 at /jenkins/workspace/0006172_home_cei-automation_main/node_modules/@playwright/test/lib/fixtures.js:78:81 17:58:31 at Object.dynatraceRegularInvoke [as doInvoke] (/apps/dynatrace-One/agent/bin/1.219.162.20210726-100948/any/nodejs/nodejsagent.js:2882:20) 17:58:31 at Object.b.safeInvoke (/apps/dynatrace-One/agent/bin/1.219.162.20210726-100948/any/nodejs/nodejsagent.js:2954:29) 17:58:31 at /apps/dynatrace-One/agent/bin/1.219.162.20210726-100948/any/nodejs/nodejsagent.js:7364:25 17:58:31 17:58:31 17:58:31 1 failed 17:58:31 [chromium] ��� src/ui/specs/simulationPage.spec.js:5:3 ��� Output Edit ��� Simulations page == 17:58:31 npm ERR! code ELIFECYCLE 17:58:31 npm ERR! errno 1 17:58:31 npm ERR! playwright@1.0.0 test-galileo-chrome:PLAYWRIGHT_BROWSERS_PATH=/jenkins/.cache/ms-playwright npx playwright test --workers=1 --project=chromium 17:58:31 npm ERR! Exit status 1 17:58:31 npm ERR! 17:58:31 npm ERR! Failed at the playwright@1.0.0 test-galileo-chrome script. 17:58:31 npm ERR! This is probably not a problem with npm. There is likely additional logging output above.