Linux系统中配置UI自动化之Chrome

适用场景:需要在Linux系统或Docker容器中运行无头模式的UI自动化测试用例。

一、Chrome浏览器

Setp1:安装

执行下载和安装:

$ yum install -y google-chrome-stable

安装完效果:

备注:如果默认源无法下载,配置源。

vi /etc/yum.repos.d/google.repo

配置源信息:

[google]
name=Google-x86_64
baseurl=http://dl.google.com/linux/rpm/stable/x86_64
enabled=1
gpgcheck=0
gpgkey=https://dl-ssl.google.com/linux/linux_signing_key.pub

Step2:修改

首先,打开程序文件:

$ vi /usr/bin/google-chrome

修改前:exec -a "$0" "$HERE/chrome" "$@"

修改后:exec -a "$0" "$HERE/chrome" "$@" --disable-gpu --no-sandbox --disable-dev-shm-usage


Step3:检查

尝试启动google-chrome浏览器,正常运行的预期效果:

二、Chromedriver驱动

资源地址:http://chromedriver.storage.googleapis.com/index.html

Step1:下载

找到与已安装的Chrome浏览器版本基本一致的chromedriver资源,执行CURL下载指令:

$ curl http://chromedriver.storage.googleapis.com/110.0.5481.77/chromedriver_linux64.zip -o /chromedriver_linux64.zip --progress

Step2:解压

使用unzip命令解压。

$ unzip chromedriver_linux64.zip

备注:如果容器内没有安装,可以使用yum安装unzip

$ yum install -y unzip

Step3:移动程序

$ mv chromedriver /usr/local/bin
3 Likes

最后还需要把这个路径添加到环境变量吗

不需要。