diff --git a/.github/vrt/approve-latest-build.sh b/.github/vrt/approve-latest-build.sh deleted file mode 100755 index 9078b2e..0000000 --- a/.github/vrt/approve-latest-build.sh +++ /dev/null @@ -1,14 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -login='{"email": "visual-regression-tracker@example.com", "password": "123456"}' -token=$(curl -sf -H 'Content-Type: application/json' -d "$login" "$VRT_APIURL/users/login" | jq -r .token) -auth="Authorization: Bearer $token" - -project=$(curl -sf -H "$auth" "$VRT_APIURL/projects" | jq -r --arg name "$VRT_PROJECT" '.[] | select(.name == $name or .id == $name) | .id') -build=$(curl -sf -H "$auth" "$VRT_APIURL/builds?projectId=$project&take=1&skip=0" | jq '.data[0]') - -# The example must have stopped the build although its test failed. -jq -e '.isRunning == false and .unresolvedCount > 0' <<<"$build" - -curl -sf -X PATCH -H "$auth" "$VRT_APIURL/builds/$(jq -r .id <<<"$build")/approve?merge=false" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 07c5dec..02ebaa0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,18 +13,22 @@ concurrency: cancel-in-progress: true jobs: - playwright: + example: + name: ${{ matrix.example }} runs-on: ubuntu-latest - timeout-minutes: 15 + strategy: + fail-fast: false + matrix: + example: [playwright] defaults: run: - shell: bash - working-directory: playwright + working-directory: ${{ matrix.example }} env: VRT_APIURL: http://localhost:4200 VRT_APIKEY: DEFAULTUSERAPIKEYTOBECHANGED VRT_PROJECT: Default project VRT_BRANCHNAME: master + VRT_ENABLESOFTASSERT: "true" steps: - uses: actions/checkout@v7 - name: Start Visual Regression Tracker @@ -37,11 +41,4 @@ jobs: - run: pwsh bin/Debug/net10.0/playwright.ps1 install --with-deps --only-shell chromium - name: Wait for Visual Regression Tracker run: timeout 180 bash -c 'until curl -s -o /dev/null http://localhost:4200; do sleep 2; done' - - name: First run fails, the screenshot has no baseline yet - run: | - if dotnet test --no-build | tee first-run.log; then exit 1; fi - grep -q 'No baseline' first-run.log - - name: Approve the new baseline - run: ../.github/vrt/approve-latest-build.sh - - name: Second run passes against the approved baseline - run: dotnet test --no-build + - run: dotnet test --no-build --output detailed diff --git a/playwright/HomePageTests.cs b/playwright/HomePageTests.cs index 74be1c2..02172c1 100644 --- a/playwright/HomePageTests.cs +++ b/playwright/HomePageTests.cs @@ -1,9 +1,7 @@ -using VisualRegressionTracker; - public class HomePageTests { [Test] - public async Task HomePageMatchesBaseline() + public async Task TrackHomePage() { await using var context = await TestSession.Browser.NewContextAsync(); var page = await context.NewPageAsync(); @@ -17,6 +15,5 @@ public async Task HomePageMatchesBaseline() viewport: $"{page.ViewportSize!.Width}x{page.ViewportSize.Height}"); TestContext.Out.WriteLine($"{result.Status}: {result.Url}"); - Assert.That(result.Status, Is.AnyOf(TestRunStatus.Ok, TestRunStatus.Approved, TestRunStatus.AutoApproved)); } } diff --git a/playwright/README.md b/playwright/README.md index 9f51136..79a922d 100644 --- a/playwright/README.md +++ b/playwright/README.md @@ -17,13 +17,14 @@ ## Run ```sh -dotnet test +dotnet test --output detailed ``` ## What to expect -- First run: the test fails with `No baseline` and a link to the test run. The VRT UI shows a build with one `New` test run, "Home page". -- Approve it in the UI. It becomes the baseline for the branch. -- Next runs pass while the page looks the same (`Ok`). When it changes, the test fails with `Difference found` and the build shows an `Unresolved` test run with the diff. Approve the change to make it the new baseline, or reject it. +`enableSoftAssert` is on, as in the other examples: the SDK writes a failed check to stderr instead of throwing, so the test passes and prints the status and a link to the test run. -`New` and `Unresolved` fail the test; `Ok`, `Approved` and `AutoApproved` pass. With `enableSoftAssert`, the SDK writes the failure to stderr instead of throwing, and the status assertion in the test fails it. +- First run: `New`, with `No baseline` on stderr. The VRT UI shows a build with one new test run, "Home page". Approve it to make it the baseline for the branch. +- Next runs: `Ok` while the page looks the same. When it changes, `Unresolved`, with `Difference found` on stderr, and the build shows the diff to approve or reject. + +Set `enableSoftAssert` to `false` to make `New` and `Unresolved` fail the test. diff --git a/playwright/vrt.json.example b/playwright/vrt.json.example index 6167913..c372ab5 100644 --- a/playwright/vrt.json.example +++ b/playwright/vrt.json.example @@ -3,5 +3,5 @@ "apiKey": "DEFAULTUSERAPIKEYTOBECHANGED", "project": "Default project", "branchName": "master", - "enableSoftAssert": false + "enableSoftAssert": true }