GitHub Actions中Playwright(v1.47) WebKit测试依赖缺失如何解决?
解决GitHub Actions中Ubuntu 24.04运行Playwright WebKit测试缺失依赖的问题
问题原因
Ubuntu 24.04(ubuntu-latest当前指向版本)默认预装的ICU库是72.x版本,而Playwright 1.47打包的WebKit依赖的是ICU 70.x版本,同时libvpx.so.7也存在版本兼容问题,导致WebKit无法启动。
解决方案
方案一:切换到Ubuntu 22.04运行器
直接将GitHub Actions的运行器指定为ubuntu-22.04,该版本的系统库版本与Playwright 1.47的WebKit依赖完全匹配,无需额外配置:
jobs: test: runs-on: ubuntu-22.04 # 替换原有的ubuntu-latest steps: - uses: actions/checkout@v4 # 后续的依赖安装、Playwright测试步骤保持不变
方案二:在Ubuntu 24.04上手动安装兼容依赖
如果必须使用Ubuntu 24.04,可通过添加旧版本Ubuntu源来获取缺失的库,步骤如下:
在Playwright安装或测试步骤前添加:
- name: Install missing WebKit dependencies run: | # 添加Ubuntu 22.04(Jammy)的软件源 echo "deb http://archive.ubuntu.com/ubuntu jammy main universe" | sudo tee /etc/apt/sources.list.d/jammy.list sudo apt-get update # 安装所需的兼容库 sudo apt-get install -y --no-install-recommends libicudata70 libicui18n70 libicuuc70 libvpx7 # 移除临时源,避免干扰后续包管理 sudo rm /etc/apt/sources.list.d/jammy.list sudo apt-get update
方案三:升级Playwright到适配Ubuntu 24.04的版本
Playwright后续版本(如1.48+)已经适配了Ubuntu 24.04的系统库,直接升级Playwright版本即可解决依赖问题:
npm install @playwright/test@latest # 或者用yarn/pnpm yarn add @playwright/test@latest pnpm add @playwright/test@latest
升级后重新运行npx playwright install-deps确保依赖安装完整。
内容的提问来源于stack exchange,提问作者Cornelius Roemer
相关产品推荐
相关产品推荐

