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

[Question] Playwright Docker image not finding browser #11719

Closed davidhprotective closed 2 years ago

davidhprotective commented 2 years ago

I have a few tests with Playwright written in .Net and I am trying to build Docker container using Playwright's image but it still fails to find browsers. The only thing I am adding on top of the existing image is .Net SDK and copying over my repository. Here is my Dockerfile:

FROM mcr.microsoft.com/playwright

RUN  apt-get update \
  && apt-get install -y wget \
  && rm -rf /var/lib/apt/lists/*

# Install .Net SDK6.0
RUN wget https://packages.microsoft.com/config/ubuntu/20.04/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
RUN dpkg -i packages-microsoft-prod.deb
RUN rm packages-microsoft-prod.deb
RUN apt-get update; \
  apt-get install -y apt-transport-https && \
  apt-get update && \
  apt-get install -y dotnet-sdk-6.0

COPY AcceptanceTests /AcceptanceTests
COPY AcceptanceTests/AcceptanceTests.csproj /AcceptanceTests
COPY Api /Api

RUN dotnet build AcceptanceTests

RUN dotnet test AcceptanceTests

When I build this Docker with docker build -t acctest -f AcceptanceTests.Dockerfile . I get below error:

#15 10.84   Failed AcceptanceTests.HomePageHeaderTests.VerifyAccountName [1 ms]
#15 10.84   Error Message:
#15 10.84    System.AggregateException : One or more errors occurred. (One or more errors occurred. (Executable doesn't exist at /ms-playwright/chromium-939194/chrome-linux/chrome
#15 10.84 ╔═════════════════════════════════════════════════════════════════════════╗
#15 10.84 ║ Looks like Playwright Test or Playwright was just installed or updated. ║
#15 10.84 ║ Please run the following command to download new browsers:              ║
#15 10.84 ║                                                                         ║
#15 10.84 ║     playwright install                                                  ║
#15 10.84 ║                                                                         ║
#15 10.84 ║ <3 Playwright Team                                                      ║

When I open the bash terminal inside the Docker container and run ls I can see that ms-playwright folder is in the root directory along with the AcceptanceTests folder which has my tests in it so I don't understand why it fails to detect it.

image

Can someone help please?

davidhprotective commented 2 years ago

I just noticed that the browser version it is looking for during the dotnet test does not match with the browser version under /ms-playwright. What should I do in this case?

davidhprotective commented 2 years ago

I noticed that browser version it is looking for is due to me using Playwright version 1.17 in my local repository because browsers.json file under the bin/Debug/.net5.0/.playwright/package/browsers.json matches with the browser version it is trying to locate in the docker when I run the test. So I went ahead and updated my Playwright version to 1.18 in my local repository and now browser version in browsers.json file matches with what comes installed in the playwright docker image. Then I went ahead and I rebuilt docker (with --no cache), but now I am getting a different error:

Error Message:
   System.AggregateException : One or more errors occurred. (One or more errors occurred. (Browser closed.
==================== Browser output: ====================
<launching> /ms-playwright/chromium-956323/chrome-linux/chrome 
--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 --no-sandbox --disable-dev-shm-usage 
--user-data-dir=/tmp/playwright_chromiumdev_profile-lP1iEF --remote-debugging-pipe --no-startup-window
<launched> pid=668
[pid=668][err] [668:668:0128/214647.950496:FATAL:ozone_platform_x11.cc(231)] Check failed: x11::Connection::Get()->Ready(). Missing X server or $DISPLAY
[pid=668][err] #0 0x55d4e2b94ae9 base::debug::CollectStackTrace()
[pid=668][err] #1 0x55d4e2afcf03 base::debug::StackTrace::StackTrace()
[pid=668][err] #2 0x55d4e2b0ff50 logging::LogMessage::~LogMessage()
[pid=668][err] #3 0x55d4e2b10a9e logging::LogMessage::~LogMessage()
[pid=668][err] #4 0x55d4dfd7cf49 ui::(anonymous namespace)::OzonePlatformX11::InitializeUI()
[pid=668][err] #5 0x55d4dfd18a17 ui::OzonePlatform::InitializeForUI()
[pid=668][err] #6 0x55d4e42d05de aura::Env::Init()
[pid=668][err] #7 0x55d4e42d057a aura::Env::CreateInstance()
[pid=668][err] #8 0x55d4e06fb3aa content::BrowserMainLoop::InitializeToolkit()
[pid=668][err] #9 0x55d4e06fbd08 content::BrowserMainRunnerImpl::Initialize()
[pid=668][err] #10 0x55d4e06f8143 content::BrowserMain()
[pid=668][err] #11 0x55d4e26a8b08 content::RunBrowserProcessMain()
[pid=668][err] #12 0x55d4e26a9e89 content::ContentMainRunnerImpl::RunBrowser()
[pid=668][err] #13 0x55d4e26a992e content::ContentMainRunnerImpl::Run()
[pid=668][err] #14 0x55d4e26a6de4 content::RunContentProcess()
[pid=668][err] #15 0x55d4e26a78f7 content::ContentMain()
[pid=668][err] #16 0x55d4df43f88b ChromeMain
[pid=668][err] #17 0x7f4f638630b3 __libc_start_main
[pid=668][err] #18 0x55d4df43f66a _start
[pid=668][err] Crash keys:
[pid=668][err]   "io_scheduler_async_stack" = "0x55D4E052D0F4 0x0"
[pid=668][err]   "variations" = "6aa15a86-86f8c66a,23a898eb-fc93cf74,5f2c0f7c-3f4a17df,69d4ebd5-3f4a17df,"
[pid=668][err]   "num-experiments" = "4"
[pid=668][err]   "switch-32" = "--enable-crashpad"
[pid=668][err]   "switch-31" = "--no-startup-window"
[pid=668][err]   "switch-30" = "--remote-debugging-pipe"
[pid=668][err]   "switch-29" = "--user-data-dir=/tmp/playwright_chromiumdev_profile-lP1iEF"
[pid=668][err]   "switch-28" = "--disable-dev-shm-usage"
[pid=668][err]   "switch-27" = "--no-sandbox"
[pid=668][err]   "switch-26" = "--export-tagged-pdf"
[pid=668][err]   "switch-25" = "--no-service-autorun"
[pid=668][err]   "switch-24" = "--use-mock-keychain"
[pid=668][err]   "switch-23" = "--password-store=basic"
[pid=668][err]   "switch-22" = "--enable-automation"
[pid=668][err]   "switch-21" = "--no-first-run"
[pid=668][err]   "switch-20" = "--metrics-recording-only"
[pid=668][err]   "switch-19" = "--force-color-profile=srgb"
[pid=668][err]   "switch-18" = "--disable-sync"
[pid=668][err]   "switch-17" = "--disable-renderer-backgrounding"
[pid=668][err]   "switch-16" = "--disable-prompt-on-repost"
[pid=668][err]   "switch-15" = "--disable-popup-blocking"
[pid=668][err]   "switch-14" = "--disable-ipc-flooding-protection"
[pid=668][err]   "switch-13" = "--disable-hang-monitor"
[pid=668][err]   "switch-12" = "--allow-pre-commit-input"
[pid=668][err]   "switch-11" = "--disable-features=ImprovedCookieControls,LazyFrameLoading,Globa"
[pid=668][err]   "switch-10" = "--disable-extensions"
[pid=668][err]   "switch-9" = "--disable-dev-shm-usage"
[pid=668][err]   "switch-8" = "--disable-default-apps"
[pid=668][err]   "switch-7" = "--disable-component-extensions-with-background-pages"
[pid=668][err]   "switch-6" = "--disable-client-side-phishing-detection"
[pid=668][err]   "switch-5" = "--disable-breakpad"
[pid=668][err]   "switch-4" = "--disable-backgrounding-occluded-windows"
[pid=668][err]   "switch-3" = "--disable-background-timer-throttling"
[pid=668][err]   "switch-2" = "--enable-features=NetworkService,NetworkServiceInProcess"
[pid=668][err]   "switch-1" = "--disable-background-networking"
[pid=668][err]   "num-switches" = "32"
[pid=668][err]   "osarch" = "x86_64"
[pid=668][err]   "pid" = "668"
[pid=668][err]   "ptype" = "browser"
[pid=668][err]
[pid=668][err] [0128/214648.119985:ERROR:file_io_posix.cc(144)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_cur_freq: No such file or directory (2)
[pid=668][err] [0128/214648.120046:ERROR:file_io_posix.cc(144)] open /sys/devices/system/cpu/cpu0/cpufreq/scaling_max_freq: No such file or directory (2)
[pid=668][err] Received signal 6
[pid=668][err] #0 0x55d4e2b94ae9 base::debug::CollectStackTrace()
[pid=668][err] #1 0x55d4e2afcf03 base::debug::StackTrace::StackTrace()
[pid=668][err] #2 0x55d4e2b945c1 base::debug::(anonymous namespace)::StackDumpSignalHandler()
[pid=668][err] #3 0x7f4f647343c0 (/usr/lib/x86_64-linux-gnu/libpthread-2.31.so+0x153bf)
[pid=668][err] #4 0x7f4f6388218b gsignal
[pid=668][err] #5 0x7f4f63861859 abort
[pid=668][err] #6 0x55d4e2b93855 base::debug::BreakDebuggerAsyncSafe()
[pid=668][err] #7 0x55d4e2b1037f logging::LogMessage::~LogMessage()
[pid=668][err] #8 0x55d4e2b10a9e logging::LogMessage::~LogMessage()
[pid=668][err] #9 0x55d4dfd7cf49 ui::(anonymous namespace)::OzonePlatformX11::InitializeUI()
[pid=668][err] #10 0x55d4dfd18a17 ui::OzonePlatform::InitializeForUI()
[pid=668][err] #11 0x55d4e42d05de aura::Env::Init()
[pid=668][err] #12 0x55d4e42d057a aura::Env::CreateInstance()
[pid=668][err] #13 0x55d4e06fb3aa content::BrowserMainLoop::InitializeToolkit()
[pid=668][err] #14 0x55d4e06fbd08 content::BrowserMainRunnerImpl::Initialize()
[pid=668][err] #15 0x55d4e06f8143 content::BrowserMain()
[pid=668][err] #16 0x55d4e26a8b08 content::RunBrowserProcessMain()
[pid=668][err] #17 0x55d4e26a9e89 content::ContentMainRunnerImpl::RunBrowser()
[pid=668][err] #18 0x55d4e26a992e content::ContentMainRunnerImpl::Run()
[pid=668][err] #19 0x55d4e26a6de4 content::RunContentProcess()
[pid=668][err] #20 0x55d4e26a78f7 content::ContentMain()
[pid=668][err] #21 0x55d4df43f88b ChromeMain
[pid=668][err] #22 0x7f4f638630b3 __libc_start_main
[pid=668][err] #23 0x55d4df43f66a _start
[pid=668][err]   r8: 0000000000000000  r9: 00007fff99f7be60 r10: 0000000000000008 r11: 0000000000000246
[pid=668][err]  r12: 00002ee8002b8780 r13: 00007fff99f7c0c0 r14: 00002ee8002b8790 r15: aaaaaaaaaaaaaaaa
[pid=668][err]   di: 0000000000000002  si: 00007fff99f7be60  bp: 00007fff99f7c0b0  bx: 00007f4f626a0e00
[pid=668][err]   dx: 0000000000000000  ax: 0000000000000000  cx: 00007f4f6388218b  sp: 00007fff99f7be60
[pid=668][err]   ip: 00007f4f6388218b efl: 0000000000000246 cgf: 002b000000000033 erf: 0000000000000000
[pid=668][err]  trp: 0000000000000000 msk: 0000000000000000 cr2: 0000000000000000
[pid=668][err] [end of stack trace]
aslushnikov commented 2 years ago

I have a few tests with Playwright written in .Net and I am trying to build Docker container using Playwright's image but it still fails to find browsers

@davidhprotective first thing first: docker images are versioned, and you should use the same version of docker image as the playwright you run.

So start your docker file like this:

FROM mcr.microsoft.com/playwright:v1.18.0

Then I went ahead and I rebuilt docker (with --no cache), but now I am getting a different error:

Your tests launch Chrome in headed mode. To fix the error, run your tests via xvfb utility that's pre-installed in the docker.

RUN xvfb-run --auto-servernum dotnet test AcceptanceTests