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
66.39k stars 3.63k forks source link

[Question] how to run tests inside docker with headless:true, want to see the browser. #18224

Closed InduKrish closed 1 year ago

InduKrish commented 2 years ago

Hi All, is there a way to run the test with headless mode: false inside docker? is there a reason why the text expects to turn on headless mode ( headless : true) while running the tests inside docker? I would like to see the browser execution while running the tests in docker.

please advise where to add xvfb-run to run tests in headless:true mode? is it inside the docker file? or something like this xvfb-run npx playwright test --reporter=line,allure-playwright,html do we have to install xvfb in docker file? Please advise?

════════════════════╗
    ║ Looks like you launched a headed browser without having a XServer running.                     ║
    ║ Set either 'headless: true' or use 'xvfb-run <your-playwright-app>' before running Playwright. ║
    ║                                                                                                ║
    ║ <3 Playwright Team                                                                             ║
═════════╝
    =========================== logs ===========================
    <launching> /ms-playwright/chromium-1019/chrome-linux/chrome --disable-field-trial-config --disable-background-networking --enable-features=NetworkService,NetworkServiceInProcess --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-back-forward-cache --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,DialMediaRouteProvider,AcceptCHFrame,AutoExpandDetailsElement,CertificateTransparencyComponentUpdater,AvoidUnnecessaryBeforeUnloadCheckSync,Translate --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 --no-sandbox --user-data-dir=/tmp/playwright_chromiumdev_profile-1cMpSY --remote-debugging-pipe --no-startup-window
    <launched> pid=397
    [pid=397][err] [397:397:1020/143410.399965:ERROR:ozone_platform_x11.cc(240)] Missing X server or $DISPLAY
    [pid=397][err] [397:397:1020/143410.400158:ERROR:env.cc(255)] The platform failed to initialize.  Exiting.
    ============================================================
aslushnikov commented 2 years ago

@InduKrish xvfb is already installed inside docker; you need to call

xvfb-run npx playwright test

inside docker so that there's an X11 display available for browsers launched from the process subtree.

dgozman commented 1 year ago

Closing as per above.

sayurionishi commented 1 year ago

Hi @aslushnikov, I was able to run my tests without an error using xvfb-run but the browser where the tests are running doesn't show. Where can I see it? Sorry, I'm running the playwright tests using github codespace and not sure where there tests would show up.

khaledtaymour-incorta commented 1 year ago

Hi @aslushnikov, I was able to run my tests without an error using xvfb-run but the browser where the tests are running doesn't show. Where can I see it? Sorry, I'm running the playwright tests using github codespace and not sure where there tests would show up.

I am facing the same issue, any help?

alexkuc commented 9 months ago

Sorry, I'm running the playwright tests using github codespace and not sure where there tests would show up

Hmmm… perhaps you would need to forward X11 from GitHub Codespace as well? I imagine that Docker container would forward X11 to GitHub Codespace but without further redirection, I imagine the output wouldn't go anyway else.

I haven't actually used GitHub Codespace and but I do use Playwright and Docker on a remote system where I had to configure X server forwarding over SSH to be able to use head-full mode.