docker内使用playwright
一、镜像使用
docker pull python:3.9-buster
二、安装playwright
镜像内执行如下指令: 1.安装playwright pip3 install playwright==1.31.1 -i https://pypi.tuna.tsinghua.edu.cn/simple 2.安装浏览器 playwright install chromium(根据情况选择浏览器) 3.修改debian源 sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list 4.更新apt-get apt-get update 5.安装中文字体,失败截图时,如果图内有中文会乱码 apt-get install ttf-wqy-microhei 6.安装playwright需要的依赖包 apt-get install -y libnss3 libx11-xcb1 libasound2 libatk-bridge2.0-0 libgtk-3-0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libgbm1 libpango-1.0-0 libcairo2 libxkbcommon0 libxslt1.1 libgtk-3-0 libdbus-glib-1-2
三、dockerfile
FROM python:3.9-buster RUN pip3 install playwright==1.31.1 -i https://pypi.tuna.tsinghua.edu.cn/simple RUN playwright install chromium RUN sed -i 's/deb.debian.org/mirrors.aliyun.com/g' /etc/apt/sources.list RUN apt-get update RUN apt-get install ttf-wqy-microhei RUN apt-get install -y libnss3 libx11-xcb1 libasound2 libatk-bridge2.0-0 libgtk-3-0 libxcomposite1 libxdamage1 libxfixes3 libxrandr2 libgbm1 libpango-1.0-0 libcairo2 libxkbcommon0 libxslt1.1 libgtk-3-0 libdbus-glib-1-2
在如上镜像内可以正常使用playwright跑前端的自动化测试了