前言

近期在公司提供的 Centos7 服务器上完成了 playwright 的安装,安装过程磕磕绊绊,回过头去翻官方说明文档才发现 Centos 并不在支持的系统范围里,加上使用的是一个相对纯净的镜像,使用默认的依赖安装命令都会报错,我这记录下遇到的问题和安装过程。主要是以下几个问题:

下边详细说下我的安装过程

playwright 安装

playwright 安装只涉及到以下两个命令(我使用的是 python 版本)

pip3 install playwright
playwright install

执行 playwright 提示缺失 GLIBC 库

完第一步安装以后,执行 playwright 会提示

/root/ui_test/lib/python3.9/site-packages/playwright/driver/node: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by /root/ui_test/lib/python3.9/site-packages/playwright/driver/node)
/root/ui_test/lib/python3.9/site-packages/playwright/driver/node: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.20' not found (required by /root/ui_test/lib/python3.9/site-packages/playwright/driver/node)
/root/ui_test/lib/python3.9/site-packages/playwright/driver/node: /lib64/libstdc++.so.6: version `CXXABI_1.3.9' not found (required by /root/ui_test/lib/python3.9/site-packages/playwright/driver/node)
/root/ui_test/lib/python3.9/site-packages/playwright/driver/node: /lib64/libstdc++.so.6: version `GLIBCXX_3.4.21' not found (required by /root/ui_test/lib/python3.9/site-packages/playwright/driver/node)
/root/ui_test/lib/python3.9/site-packages/playwright/driver/node: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by /root/ui_test/lib/python3.9/site-packages/playwright/driver/node)
/root/ui_test/lib/python3.9/site-packages/playwright/driver/node: /lib64/libc.so.6: version `GLIBC_2.25' not found (required by /root/ui_test/lib/python3.9/site-packages/playwright/driver/node)

主要提示的内容是 GLIBC 和 CXXABI 这两个缺失动态链接库的特定版本,既然缺失的话,我们补充安装这两个链接库既可以。

wget http://ftp.gnu.org/gnu/glibc/glibc-2.28.tar.gz
tar -xzvf glibc-2.28.tar.gz
cd glibc-2.28

## 创建临时文件
mkdir build && cd build
## 编译这一步一般会提示编译工具过旧
../configure --prefix=/usr --disable-profile --enable-add-ons --with-headers=/usr/include --with-binutils=/usr/bin --disable-werror

make
make install

直接安装会提示编译工具过旧

These critical programs are missing or too old: make compiler

需要先做如下处理

安装 GLIBC 提示需要升级 gcc 和 make 版本

升级 gcc

# 安装devtoolset-8-gcc
 yum install centos-release-scl
 yum install devtoolset-8
 scl enable devtoolset-8 -- bash

# 启用工具
 source /opt/rh/devtoolset-8/enable 

# 安装GCC-8
 yum install -y devtoolset-8-gcc devtoolset-8-gcc-c++ devtoolset-8-binutils

# 设置环境变量
 echo "source /opt/rh/devtoolset-8/enable" >> /etc/profile
 source /etc/profile

升级 make

# 下载并解压安装包
 wget https://ftp.gnu.org/gnu/make/make-4.3.tar.gz
 tar -xzvf make-4.3.tar.gz 
 cd make-4.3/

# 安装到指定目录
 ./configure  --prefix=/usr/local/make
 make
 make install 

# 创建软链接
 cd /usr/bin/
 mv make make.bak # backup
 ln -sv /usr/local/make/bin/make /usr/bin/make

完成后再重新执行第一步的编译即可

安装 CXXABI 库

接下来继续完成 CXXABI 库安装

# 创建临时安装文件目录
mkdir -p ~/work && cd ~/work
yum install libstdc++.so.6 -y
# 查看动态链接库 -- 发现并没有需要的1.3.9
strings /usr/lib/libstdc++.so.6 | grep 'CXXABI'
# 下载需要的版本库,之后软连接到运行系统上
wget http://ftp.de.debian.org/debian/pool/main/g/gcc-8/libstdc++6_8.3.0-6_amd64.deb
ar -x libstdc++6_8.3.0-6_amd64.deb
tar -xvf data.tar.xz
cp usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.25 /usr/lib64/
find / -name "libstdc++*"
# 删除低版本库的软连接
rm -rf /usr/lib64/libstdc++.so.6
ll /usr/lib64/libstd*
ln -s /usr/lib64/libstdc++.so.6.0.25 /usr/lib64/libstdc++.so.6

# 移除临时安装文件目录
cd ~ && rm -rf ~/work
# 或者删除文件与目录
rm -rf glibc-2.28 usr make-4.3 libstdc++6_8.3.0-6_amd64.deb make-4.3.tar.gz glibc-2.28.tar.gz data.tar.xz control.tar.xz
# 检验
playwright install

安装 playwright 浏览器提示缺失依赖

接着上边命令执行 playwright install 就不会报错了,但是再执行 playwright 会提示缺失依赖

BrowserType.launch: 
╔══════════════════════════════════════════════════════╗
║ Host system is missing dependencies to run browsers. ║
║ Please install them with the following command:      ║
║                                                      ║
║     playwright install-deps                          ║
║                                                      ║
║ Alternatively, use apt:                              ║
║     apt-get install libatk1.0-0\                     ║
║         libatk-bridge2.0-0\                          ║
║         libatspi2.0-0\                               ║
║         libxcomposite1\                              ║
║         libxdamage1\                                 ║
║         libxfixes3\                                  ║
║         libxrandr2\                                  ║
║         libgbm1\                                     ║
║         libxkbcommon0\                               ║
║         libpango-1.0-0\                              ║
║         libcairo2                                    ║
║                                                      ║
║ <3 Playwright Team                                   ║
╚══════════════════════════════════════════════════════╝

上边提示的缺失依赖包都是 Ubuntu 的,我使用 Centos 的话需要按照对应的依赖

yum -y install libXcomposite libXtst gtk3 atk at-spi2-atk cups-libs libxkbcommon libXdamage libXrandr mesa-libgbm alsa-lib-devel

yum -y install fontconfig
yum -y install cjkuni-ukai-fonts cjkuni-uming-fonts
fc-cache -fv

升级和安装完成后导致系统中文字符乱码

一般完成如上安装升级再执行 playwright 就不会报错了,但是我的测试集成在 Jenkins 上,放的是一个中文文件夹,实际构建的时候又出现了下边的报错

Caused by: java.nio.file.InvalidPathException: Malformed input or input contains unmappable characters: /var/lib/jenkins/workspace/????????????-???????????????
    at java.base/sun.nio.fs.UnixPath.encode(UnixPath.java:145)
    at java.base/sun.nio.fs.UnixPath.<init>(UnixPath.java:69)
    at java.base/sun.nio.fs.UnixFileSystem.getPath(UnixFileSystem.java:279)
    at java.base/java.io.FilePermission.<clinit>(FilePermission.java:207)

中文部分都是问号,看起来是系统中文字符编码出了问题,也不知道是哪个升级环节影响了,一番查找后,使用下边这个命令解决了。

localedef -v -c -i en_US -f UTF-8 en_US.UTF-8

如上就是这一次的安装记录,希望能帮助遇到同样问题的伙伴。


↙↙↙阅读原文可查看相关链接,并与作者交流