Skip to content

Commit

Permalink
Merge pull request #36 from currents-dev/feat/last-failed-example
Browse files Browse the repository at this point in the history
Add examples for last failed tests
  • Loading branch information
agoldis authored Sep 30, 2024
2 parents a14ba28 + 7bf2c58 commit 5856465
Show file tree
Hide file tree
Showing 7 changed files with 135 additions and 62 deletions.
55 changes: 0 additions & 55 deletions .github/full-parallel-prod.yml

This file was deleted.

9 changes: 5 additions & 4 deletions .github/workflows/rerun-shards-pwc.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: demo.playwright.failed-only-shards
name: failed-only-shards

on:
workflow_dispatch:
Expand Down Expand Up @@ -35,8 +35,8 @@ jobs:
npx playwright install chrome
npm install -g @currents/cmd@beta
- name: Load last run from cache
env:
DEBUG: "currents,currents:*"
# env:
# DEBUG: "currents,currents:*"
run: |
npx currents cache get \
--preset last-run \
Expand All @@ -56,9 +56,10 @@ jobs:
# env:
# DEBUG: "currents,currents:*"
if: ${{ always() }}
# --pw-output-dir is the directory where the test results are stored
run: |
npx currents cache set \
--preset last-run \
--pw-output-dir basic/test-results \ # This is the directory where the test results are stored
--pw-output-dir basic/test-results \
--matrix-index ${{ matrix.shard }} \
--matrix-total ${{ strategy.job-total }}
65 changes: 65 additions & 0 deletions .github/workflows/rerun-shards-reporter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: failed-only-reporter

on:
push:

jobs:
test-reporter:
strategy:
fail-fast: false
matrix:
shard: [1, 2, 3]
timeout-minutes: 60
runs-on: ubuntu-latest
container: mcr.microsoft.com/playwright:latest
env:
CURRENTS_PROJECT_ID: bnsqNa
CURRENTS_RECORD_KEY: ${{ secrets.CURRENTS_RECORD_KEY }}
CURRENTS_CI_BUILD_ID: reporter-${{ github.repository }}-${{ github.run_id }}-${{ github.run_attempt }}
CURRENTS_API_URL: ${{ secrets.CURRENTS_API_URL }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}

# https://github.com/actions/runner-images/issues/6775
- run: |
echo "$GITHUB_WORKSPACE"
git config --global --add safe.directory "$GITHUB_WORKSPACE"
- uses: actions/setup-node@v4
with:
node-version: "20.x"

- name: Install dependencies
run: |
npm ci
npx playwright install chrome
npm install -g @currents/cmd@beta
- name: Load last run from cache
# env:
# DEBUG: "currents,currents:*"
run: |
npx currents cache get \
--preset last-run \
--preset-output .preset_output \
--matrix-index ${{ matrix.shard }} \
--matrix-total ${{ strategy.job-total }}
echo "EXTRA_PW_FLAGS=$(cat .preset_output)" >> $GITHUB_ENV
- name: Playwright Tests
working-directory: ./basic
run: |
COMMAND="npx playwright test --config playwright.config.reporter.ts $EXTRA_PW_FLAGS"
echo "Running command: $COMMAND"
$COMMAND
- name: Cache the last run results
# env:
# DEBUG: "currents,currents:*"
if: ${{ always() }}
run: |
npx currents cache set \
--preset last-run \
--pw-output-dir basic/test-results \
--matrix-index ${{ matrix.shard }} \
--matrix-total ${{ strategy.job-total }}
56 changes: 56 additions & 0 deletions .github/workflows/reruns-or8n.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: failed-only-or8n

on:
push:

jobs:
test-or8n:
strategy:
fail-fast: false
matrix:
shard: [1, 2, 3]
timeout-minutes: 60
runs-on: ubuntu-latest
container: mcr.microsoft.com/playwright:latest
env:
CURRENTS_PROJECT_ID: bnsqNa
CURRENTS_RECORD_KEY: ${{ secrets.CURRENTS_RECORD_KEY }}
CURRENTS_CI_BUILD_ID: ${{ github.repository }}-${{ github.run_id }}-${{ github.run_attempt }}
CURRENTS_API_KEY: ${{ secrets.CURRENTS_API_KEY }}
steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.ref }}

# https://github.com/actions/runner-images/issues/6775
- run: |
echo "$GITHUB_WORKSPACE"
git config --global --add safe.directory "$GITHUB_WORKSPACE"
- uses: actions/setup-node@v4
with:
node-version: "20.x"

- name: Install dependencies
run: |
npm ci
npx playwright install chrome
npm install -g @currents/cmd@beta
- name: Resolve Playwright options
# --output basic/test-results/.last-run.json should point to the directory where the test results are stored
run: |
PREVIOUS_CI_BUILD_ID="${GITHUB_REPOSITORY}-${GITHUB_RUN_ID}-$((GITHUB_RUN_ATTEMPT - 1))"
EXTRA_PW_FLAGS=""
if [ ${{ github.run_attempt }} -gt 1 ]; then
if npx currents api get-run --pw-last-run --ci-build-id
$PREVIOUS_CI_BUILD_ID --output basic/test-results/.last-run.json; then
EXTRA_PW_FLAGS="--last-failed"
fi
fi
echo "EXTRA_PW_FLAGS=$EXTRA_PW_FLAGS" >> $GITHUB_ENV
- name: Playwright Tests
working-directory: ./basic
run: |
COMMAND="npx pwc-p ${{ env.EXTRA_PW_FLAGS }}"
echo "Running command: $COMMAND"
eval $COMMAND
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,12 @@ Examples of various variants of integrating Currents with Playwright on GitHub A

- [argos-example.yml](.github/workflows/argos-example.yml) - parallel run using Argos CI and Currents orchestration.

### Reruns only the failed tests

- [rerun-shards-pwc.yml](.github/workflows/rerun-shards-pwc.yml) - rerun only the tests that failed in the previous run, using `pwc` helper command that is included in `@currents/playwright` package.
- [rerun-shards-reporter.yml](.github/workflows/rerun-shards-reporter.yml) - rerun only the tests that failed in the previous run, using reporter explicitly configured in `playwright.config.ts`
- [reruns-or8n.yml](.github/workflows/reruns-or8n.yml) - rerun only the tests that failed in the previous orchestrated run

## Additional resources

- Playwright Features on Currents: https://currents.dev/playwright
Expand Down
4 changes: 2 additions & 2 deletions basic/2-actions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test.beforeEach(async ({ page }) => {
* by the completed items to ensure that the item is not visible anymore.
* @see https://playwright.dev/docs/api/class-locator
*/
test("basic interaction @basic", async ({ page }, testInfo) => {
test.skip("basic interaction @basic", async ({ page }, testInfo) => {
const inputBox = page.locator("input.new-todo");
const todoList = page.locator(".todo-list");

Expand All @@ -33,7 +33,7 @@ test("basic interaction @basic", async ({ page }, testInfo) => {
* Playwright supports different selector engines which you can combine with '>>'.
* @see https://playwright.dev/docs/selectors
*/
test("element selectors @basic", async ({ page }) => {
test.skip("element selectors @basic", async ({ page }) => {
// When no selector engine is specified, Playwright will use the css selector engine.
await page.type(".header input", "Learn Playwright");
// So the selector above is the same as the following:
Expand Down
2 changes: 1 addition & 1 deletion basic/3-assertions.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test.beforeEach(async ({ page }) => {
*/
test("should be able to use assertions", async ({ page }) => {
await test.step("toHaveTitle/toHaveURL", async () => {
await expect(page).toHaveTitle("Vanilla ES6 • TodoMVC");
await expect(page).toHaveTitle("TodoMVC: Backbone");
await expect(page).toHaveURL("https://todomvc.com/examples/backbone/dist/");
});

Expand Down

0 comments on commit 5856465

Please sign in to comment.