自托管Windows Runner上GitHub Actions中Playwright测试运行失败问题
Playwright测试集成GitHub Actions自托管Windows Runner连接问题
在将Playwright测试集成到GitHub Actions时,使用自托管Windows Runner遇到以下问题:本地服务器已启动,但测试无法连接,导致测试无法运行。本地运行测试一切正常,但GitHub Actions输出显示测试无法连接服务器。
最初的GitHub Actions工作流步骤
steps: - name: Checkout code uses: actions/checkout@v4 - name: Install Nodejs uses: actions/setup-node@v4 with: node-version: 22.14.0 - name: Install dependencies run: npm install - name: Run local server run: start /B npm run start shell: cmd - name: Install npm dependencies working-directory: testing\playwright run: | echo "Installing npm dependencies..." npm ci shell: cmd - name: Install playwright working-directory: testing\playwright run: | echo "Installing playwright..." npx playwright install --with-deps shell: cmd - name: Run playwright tests working-directory: testing\playwright run: | echo "Running Playwright tests..." npm run playwright:smoke:local:ci shell: cmd
已尝试的解决方案
方案1:添加超时和等待加载事件
为测试添加超时并等待加载事件,问题未解决。
方案2:通过Playwright配置管理服务器
修改Playwright配置,使用webServer字段管理服务器,但服务器持续超时,GitHub Actions仍报错。配置如下:
webServer: { command: "cd ../../ && npm run start", url: "http://127.0.0.1:8080/", reuseExistingServer: true, timeout: 300000, },
方案3:通过脚本文件运行测试
尝试用脚本文件运行测试,工作流步骤显示成功,但无测试报告输出,上传制品时提示No files found in the path,无法生成并上传制品。
相关工作流步骤:
- name: Run playwright tests run: | echo "Running Playwright tests..." cd testing\playwright .\scripts\run-playwright-gh.sh shell: cmd
脚本内容:
#!/bin/env sh # Install dependencies npm ci # Install Playwright browsers npx playwright install --with-deps # Enable debugging set -x # Run the Playwright smoke test suite echo "====Running Smoke Test Suite====" npm run playwright:smoke:local:ci
内容的提问来源于stack exchange,提问作者pogbamessi




