Dockerfile
FROM ubuntu
LABEL maintainer "langhuang521@l63.com"
ENV TZ=Asia/Shanghai
#设置时区
#安装python3依赖与下载安装包
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo '$TZ' > /etc/timezone \
&& apt update \
&& apt install wget gcc make zlib* -y \
&& wget https://www.python.org/ftp/python/3.8.18/Python-3.8.18.tgz \
&& tar -zxvf Python-3.8.18.tgz\
&& cd Python-3.8.18 \
&& ./configure \
&& make \
&& make install \
&& cd .. && rm -rf Python* \
&& ln -s /usr/local/bin/python3 /usr/bin/python3 \
&& ln -s /usr/local/bin/pip3 /usr/bin/pip\
&& pip3 install pytest-playwright -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com \
&& pip3 install --upgrade pip -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com\
&& playwright install \
&& playwright install-deps \
&& apt install vim -y
构建镜像命令:
docker build -t pytest-playwright:0.4.4 .
运行并验证镜像
启动容器:
docker run -it --rm pytest-playwright:0.4.4 bash
vim test_demo.py
:
import pytest
from playwright.sync_api import Page
def test_baidu_com(page: Page):
page.goto("https://www.baidu.com")
# xpath定位输入框,输入文本内容
page.fill('//*[@id="kw"]', "秦时明月")
# css点位点击“百度一下”按钮
page.click('#su')
# 打印title名称
print(page.title)
运行镜像:pytest test_demo.py