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.74k stars 3.58k forks source link

[QUESTION] Unable to launch browser in docker with xvfb headful mode #19472

Closed vinodreddy-bs closed 1 year ago

vinodreddy-bs commented 1 year ago

Context:

I am using playwright with mocha. When running tests locally in parallel everything works fine [headless: false as I am doing chrome extension testing via GUI]

When running the tests in a docker container, it started failing with browserType.launchPersistentContext: Browser closed.

Dockerfile:

FROM --platform=linux/amd64 mcr.microsoft.com/playwright:v1.27.0-focal

RUN apt-get update; apt-get clean

RUN apt-get update; apt-get -y install curl

RUN curl -LO https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
RUN apt-get install -y ./google-chrome-stable_current_amd64.deb
RUN rm google-chrome-stable_current_amd64.deb

COPY . /home/apps/

WORKDIR /home/apps

Test Setup --> [I am launching and closing the browser in beforEeach and afterEach functions]

const { chromium } = require("playwright");
const path = require("path");
const assert = require("node:assert");
const addContext = require("mochawesome/addContext");

const extensionPath = path.resolve(__dirname, "../../extension");
process.env.PW_CHROMIUM_ATTACH_TO_OTHER = "1";
exports.mochaHooks = {
  async beforeEach() {
    this.browser = await chromium.launchPersistentContext("", {
      headless: false,
      // executablePath: "/usr/bin/google-chrome",
      args: [
        `--disable-extensions-except=${extensionPath}`,
        `--load-extension=${extensionPath}`,
        '--start-maximized',
        '--disable-dev-shm-usage',
        '--no-sandbox',
        // `--display=${process.env.DISPLAY}`
      ],
      devtools: true,
      viewport: null,
      no_viewport: true,
    });

    //Fetching devtools panel as a page
    this.devtools = this.browser.pages().find((page) => page.url().includes("devtools://devtools/bundled/devtools_app.html"));
    assert(this.devtools);
    this.page = this.browser.pages().find((page) => page.url().includes("about:blank"));
    assert(this.page);
    await this.page.goto("example.com", { waitUntil: "domcontentloaded" });

    // Dock devtools to bottom and select extension panel
    await this.devtools.getByRole("button", { name: "Customize and control DevTools" }).click();
    await this.devtools.getByRole("button", { name: "Dock to bottom" }).click();
    await this.devtools.getByRole("tab", { name: "Any" }).click();

    //Closing the extension auto opened page
    const extensionPage = this.browser.pages().find((page) => page.url().includes("test/chrome"));
    assert(extensionPage);
    await extensionPage.close();

    //Fetching extension as a frame
    this.extensionPanel = await this.devtools.frameLocator('iframe[src*="index.html"]');
  },

  async afterEach() {
    if (this.currentTest.state !== "passed") {
      const screenshot_file_dir = "./reports/screenshots/" + this.currentTest.parent.title.replaceAll(" ", "");
      const screenshot_file_name = new Date().toJSON() + ".png";
      const screenshot_file_path = screenshot_file_dir + "/" + screenshot_file_name;
      await new Promise(function (resolve) {
        setTimeout(resolve, 1500);
      });
      await this.extensionPanel.locator("html").screenshot({ path: screenshot_file_path });
      addContext(this, screenshot_file_path);
    }
    await this.browser.close();
  },
};

after running tests in parallel inside a container with xvfb-run --auto-servernum npm run test, it's throwing the below error

browserType.launchPersistentContext: Browser closed.
==================== Browser output: ====================
<launching> /ms-playwright/chromium-1033/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-component-update --no-default-browser-check --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 --auto-open-devtools-for-tabs --no-sandbox --disable-extensions-except=/home/apps/a11y_extension/extension --load-extension=/home/apps/a11y_extension/extension --start-maximized --no-sandbox --user-data-dir=/tmp/playwright_chromiumdev_profile-TAP9k6 --remote-debugging-pipe about:blank
<launched> pid=1030
[pid=1030][err] [1215/111730.136246:ERROR:stack_trace_posix.cc(711)] Failed to parse the contents of /proc/self/maps
[pid=1030][err] [1215/111731.911961:ERROR:stack_trace_posix.cc(711)] Failed to parse the contents of /proc/self/maps
[pid=1030][err] [1215/111731.923871:ERROR:stack_trace_posix.cc(711)] Failed to parse the contents of /proc/self/maps
[pid=1030][err] [1065:1065:1215/111731.964453:FATAL:zygote_main_linux.cc(162)] Check failed: sandbox::ThreadHelpers::IsSingleThreaded().
[pid=1030][err] #0 0x0040077dcb92 base::debug::CollectStackTrace()
[pid=1030][err] #1 0x00400774ce13 base::debug::StackTrace::StackTrace()
[pid=1030][err] #2 0x004007749e6f logging::LogMessage::~LogMessage()
[pid=1030][err] #3 0x00400774ad3e logging::LogMessage::~LogMessage()
[pid=1030][err] #4 0x00400728ba34 content::ZygoteMain()
[pid=1030][err] #5 0x0040072860f4 content::RunZygote()
[pid=1030][err] #6 0x004007286e92 content::RunOtherNamedProcessTypeMain()
[pid=1030][err] #7 0x004007287d1d content::ContentMainRunnerImpl::Run()
[pid=1030][err] #8 0x004007284c16 content::RunContentProcess()
[pid=1030][err] #9 0x00400728552f content::ContentMain()
[pid=1030][err] #10 0x0040037c7205 ChromeMain
[pid=1030][err] #11 0x00401034b083 __libc_start_main
[pid=1030][err] #12 0x0040037c702a _start
[pid=1030][err] Crash keys:
[pid=1030][err]   "switch-5" = "--change-stack-guard-on-fork=enable"
[pid=1030][err]   "switch-4" = "--user-data-dir=/tmp/playwright_chromiumdev_profile-TAP9k6"
[pid=1030][err]   "switch-3" = "--enable-crash-reporter=,"
[pid=1030][err]   "switch-2" = "--crashpad-handler-pid=1040"
[pid=1030][err]   "switch-1" = "--no-sandbox"
[pid=1030][err]   "num-switches" = "6"
[pid=1030][err]
[pid=1030][err] [1063:1063:1215/111731.949458:FATAL:zygote_main_linux.cc(162)] Check failed: sandbox::ThreadHelpers::IsSingleThreaded().
[pid=1030][err] #0 0x0040077dcb92 base::debug::CollectStackTrace()
[pid=1030][err] #1 0x00400774ce13 base::debug::StackTrace::StackTrace()
[pid=1030][err] #2 0x004007749e6f logging::LogMessage::~LogMessage()
[pid=1030][err] #3 0x00400774ad3e logging::LogMessage::~LogMessage()
[pid=1030][err] #4 0x00400728ba34 content::ZygoteMain()
[pid=1030][err] #5 0x0040072860f4 content::RunZygote()
[pid=1030][err] #6 0x004007286e92 content::RunOtherNamedProcessTypeMain()
[pid=1030][err] #7 0x004007287d1d content::ContentMainRunnerImpl::Run()
[pid=1030][err] #8 0x004007284c16 content::RunContentProcess()
[pid=1030][err] #9 0x00400728552f content::ContentMain()
[pid=1030][err] #10 0x0040037c7205 ChromeMain
[pid=1030][err] #11 0x00401034b083 __libc_start_main
[pid=1030][err] #12 0x0040037c702a _start
[pid=1030][err] Crash keys:
[pid=1030][err]   "switch-6" = "--change-stack-guard-on-fork=enable"
[pid=1030][err]   "switch-5" = "--user-data-dir=/tmp/playwright_chromiumdev_profile-TAP9k6"
[pid=1030][err]   "switch-4" = "--enable-crash-reporter=,"
[pid=1030][err]   "switch-3" = "--crashpad-handler-pid=1040"
[pid=1030][err]   "switch-2" = "--no-sandbox"
[pid=1030][err]   "switch-1" = "--no-zygote-sandbox"
[pid=1030][err]   "num-switches" = "7"
[pid=1030][err]
[pid=1030][err] qemu: uncaught target signal 5 (Trace/breakpoint trap) - core dumped
[pid=1030][err] qemu: uncaught target signal 5 (Trace/breakpoint trap) - core dumped
[pid=1030][err] [1030:1074:1215/111732.722647:ERROR:file_path_watcher_inotify.cc(333)] inotify_init() failed: Function not implemented (38)
[pid=1030][err] [1215/111732.779085:ERROR:scoped_ptrace_attach.cc(27)] ptrace: Function not implemented (38)
[pid=1030][err] Assertion failed: p_rcu_reader->depth != 0 (/qemu/include/qemu/rcu.h: rcu_read_unlock: 101)
=========================== logs ===========================
<launching> /ms-playwright/chromium-1033/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-component-update --no-default-browser-check --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 --auto-open-devtools-for-tabs --no-sandbox --disable-extensions-except=/home/apps/a11y_extension/extension --load-extension=/home/apps/a11y_extension/extension --start-maximized --no-sandbox --user-data-dir=/tmp/playwright_chromiumdev_profile-TAP9k6 --remote-debugging-pipe about:blank
<launched> pid=1030
[pid=1030][err] [1215/111730.136246:ERROR:stack_trace_posix.cc(711)] Failed to parse the contents of /proc/self/maps
[pid=1030][err] [1215/111731.911961:ERROR:stack_trace_posix.cc(711)] Failed to parse the contents of /proc/self/maps
[pid=1030][err] [1215/111731.923871:ERROR:stack_trace_posix.cc(711)] Failed to parse the contents of /proc/self/maps
[pid=1030][err] [1065:1065:1215/111731.964453:FATAL:zygote_main_linux.cc(162)] Check failed: sandbox::ThreadHelpers::IsSingleThreaded().
[pid=1030][err] #0 0x0040077dcb92 base::debug::CollectStackTrace()
[pid=1030][err] #1 0x00400774ce13 base::debug::StackTrace::StackTrace()
[pid=1030][err] #2 0x004007749e6f logging::LogMessage::~LogMessage()
[pid=1030][err] #3 0x00400774ad3e logging::LogMessage::~LogMessage()
[pid=1030][err] #4 0x00400728ba34 content::ZygoteMain()
[pid=1030][err] #5 0x0040072860f4 content::RunZygote()
[pid=1030][err] #6 0x004007286e92 content::RunOtherNamedProcessTypeMain()
[pid=1030][err] #7 0x004007287d1d content::ContentMainRunnerImpl::Run()
[pid=1030][err] #8 0x004007284c16 content::RunContentProcess()
[pid=1030][err] #9 0x00400728552f content::ContentMain()
[pid=1030][err] #10 0x0040037c7205 ChromeMain
[pid=1030][err] #11 0x00401034b083 __libc_start_main
[pid=1030][err] #12 0x0040037c702a _start
[pid=1030][err] Crash keys:
[pid=1030][err]   "switch-5" = "--change-stack-guard-on-fork=enable"
[pid=1030][err]   "switch-4" = "--user-data-dir=/tmp/playwright_chromiumdev_profile-TAP9k6"
[pid=1030][err]   "switch-3" = "--enable-crash-reporter=,"
[pid=1030][err]   "switch-2" = "--crashpad-handler-pid=1040"
[pid=1030][err]   "switch-1" = "--no-sandbox"
[pid=1030][err]   "num-switches" = "6"
[pid=1030][err]
[pid=1030][err] [1063:1063:1215/111731.949458:FATAL:zygote_main_linux.cc(162)] Check failed: sandbox::ThreadHelpers::IsSingleThreaded().
[pid=1030][err] #0 0x0040077dcb92 base::debug::CollectStackTrace()
[pid=1030][err] #1 0x00400774ce13 base::debug::StackTrace::StackTrace()
[pid=1030][err] #2 0x004007749e6f logging::LogMessage::~LogMessage()
[pid=1030][err] #3 0x00400774ad3e logging::LogMessage::~LogMessage()
[pid=1030][err] #4 0x00400728ba34 content::ZygoteMain()
[pid=1030][err] #5 0x0040072860f4 content::RunZygote()
[pid=1030][err] #6 0x004007286e92 content::RunOtherNamedProcessTypeMain()
[pid=1030][err] #7 0x004007287d1d content::ContentMainRunnerImpl::Run()
[pid=1030][err] #8 0x004007284c16 content::RunContentProcess()
[pid=1030][err] #9 0x00400728552f content::ContentMain()
[pid=1030][err] #10 0x0040037c7205 ChromeMain
[pid=1030][err] #11 0x00401034b083 __libc_start_main
[pid=1030][err] #12 0x0040037c702a _start
[pid=1030][err] Crash keys:
[pid=1030][err]   "switch-6" = "--change-stack-guard-on-fork=enable"
[pid=1030][err]   "switch-5" = "--user-data-dir=/tmp/playwright_chromiumdev_profile-TAP9k6"
[pid=1030][err]   "switch-4" = "--enable-crash-reporter=,"
[pid=1030][err]   "switch-3" = "--crashpad-handler-pid=1040"
[pid=1030][err]   "switch-2" = "--no-sandbox"
[pid=1030][err]   "switch-1" = "--no-zygote-sandbox"
[pid=1030][err]   "num-switches" = "7"
[pid=1030][err]
[pid=1030][err] qemu: uncaught target signal 5 (Trace/breakpoint trap) - core dumped
[pid=1030][err] qemu: uncaught target signal 5 (Trace/breakpoint trap) - core dumped
[pid=1030][err] [1030:1074:1215/111732.722647:ERROR:file_path_watcher_inotify.cc(333)] inotify_init() failed: Function not implemented (38)
[pid=1030][err] [1215/111732.779085:ERROR:scoped_ptrace_attach.cc(27)] ptrace: Function not implemented (38)
[pid=1030][err] Assertion failed: p_rcu_reader->depth != 0 (/qemu/include/qemu/rcu.h: rcu_read_unlock: 101)
============================================================

Please help where I am doing wrong?

yury-s commented 1 year ago

What is the host system (the one where you launch docker) where it is failing?

If you are running docker on apple m1 machine, you need to use docker image for aarch64 instead of amd64.

vinodreddy-bs commented 1 year ago

It’s Mac M1. Trying with the above solution

On Thu, 15 Dec 2022 at 11:50 PM, Yury Semikhatsky @.***> wrote:

What is the host system where it is failing?

— Reply to this email directly, view it on GitHub https://github.com/microsoft/playwright/issues/19472#issuecomment-1353521289, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZCXZEM6TME6VNCYMLGNAMTWNNOOBANCNFSM6AAAAAAS7TWHGU . You are receiving this because you authored the thread.Message ID: @.***>

vinodreddy-bs commented 1 year ago

Now I am getting, dependency issues for chrome after changing Docker file to FROM --platform=linux/aarch64 mcr.microsoft.com/playwright:v1.27.0-focal

My goal is to run playwright tests on a server in parallel with headful. OS can be Ubuntu. Not sure what's happening here.

without chrome, it worked. What is the best config to run playwright tests on a server in headful?

vipinphogat91 commented 11 months ago

Did you find the solution to launch the chrome? I am trying to run playwright inside docker. The browser is working fine when running in headless mode but i am unable to view the broswer when running the test cases in headed mode