如何从Docker容器中生成带有playwright和codegen的测试?

pwuypxnk  于 2023-01-29  发布在  Docker
关注(0)|答案(1)|浏览(297)

我正在使用他们的标准映像mcr.microsoft.com/playwright:v1.28.1-focal。当尝试从我的Docker容器启动命令yarn playwright codegen wikipedia.org时(为了示例),我收到以下错误:

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.

我不想运行它作为无头,因为我不想生成测试。不知道如何设置一个Xserver为我的目的,和文件似乎没有提到这个问题。
任何帮助都很感激

brgchamk

brgchamk1#

我也经常遇到同样的问题,这个解决方案非常适合我:
停靠文件:

FROM mcr.microsoft.com/playwright/python:v1.30.0-focal 

RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y xvfb
RUN apt-get install -qqy x11-apps

# chromium dependencies
RUN apt-get install -y libnss3 \
                       libxss1 \
                       libasound2 \
                       fonts-noto-color-emoji

# additional actions related to your project

ENTRYPOINT ["/bin/sh", "-c", "/usr/bin/xvfb-run -a $@", ""]

docker-compose.yml

service_name:
    build: . 
    init: true
    command: # command depending on a project
    environment:
      - DISPLAY=:0
    volumes:
      - /tmp/.X11-unix:/tmp/.X11-unix

希望能有所帮助

相关问题