背景
我有一個 Playwright 測驗,我可以在所有 3 個瀏覽器引擎中使用 VS Code 在本地運行:Chromium、Firefox 和 WebKit。測驗成功地針對本地運行的應用程式和部署到預生產環境的應用程式運行。
考試:
test('that clicking link navigates to the next page', async ({ page }) => {
await page.goto('/relative/url');
await page.locator('hyperlink:has-text("relative url")').getByRole('link').click();
await page.waitForNavigation();
await expect(page).toHaveURL('https://www.example.com/relative/url');
});
部分Playwright.config.ts檔案:
use: {
...
baseURL: 'https://www.example.com',
...
},
應用結構:
- My app
- Deployment
- azure-pipelines.yml
- src
- tests
- playwright.config.ts
Azure DevOps 管道階段,其中大部分是從Playwright Azure 管道檔案中復制的
- stage: PlaywrightTests
dependsOn:
- PreprodDeployment
jobs:
- deployment: PlaywrightTests
pool:
vmImage: ubuntu-20.04
container: mcr.microsoft.com/playwright:v1.27.0-focal
environment: testing
strategy:
runOnce:
deploy:
steps:
- checkout: self
- task: NodeTool@0
inputs:
versionSpec: '16.13.0'
- task: Bash@3
displayName: 'Run Playwright tests'
inputs:
workingDirectory: 'tests'
targetType: 'inline'
failOnStderr: true
# env: # Unexpected property. Fails pipeline.
# CI: true
script: |
npm install
npx playwright test
問題
但是,當 Playwright 從 Azure DevOps 管道運行我的測驗時,測驗失敗。
管道故障:
1) links.spec.ts:3:1 ? that clicking link navigates to the next page ===============
page.goto: Protocol error (Page.navigate): Cannot navigate to invalid URL
=========================== logs ===========================
navigating to "/relative/url", waiting until "load"
============================================================
3 | test('that clicking link navigates to the next page', async ({ page }) => {
4 |
> 5 | await page.goto('/relative/url');
| ^
6 | await page.locator('hyperlink:has-text("relative url")').getByRole('link').click();
7 | await page.waitForNavigation();
8 |
at /__w/1/s/tests/links.spec.ts:5:14
1 failed
links.spec.ts:3:1 ? that clicking link navigates to the next page ================
##[error]Bash exited with code '1'.
我可以看到管道沒有使用baseURL來自playwright.config.ts。
問題
如何修復azure-pipeline.yml它以使其使用playwright.config.ts'sbaseURL值?
uj5u.com熱心網友回復:
Playwright 需要從包含該playwright.config.ts檔案的檔案夾中運行。
嘗試將您workingDirectory的 Bash 步驟更改為'./'
uj5u.com熱心網友回復:
您可以更新該npx playwright test行以顯式傳遞組態檔路徑嗎?
script: |
npm install
npx playwright test --config=../playwright.config.ts
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/520983.html
