Skip to content

Commit

Permalink
E2e increase randomness (#1169)
Browse files Browse the repository at this point in the history
* fix: increase randomness in correction-death dates

* feat: save trace on failure

* fix: make matching more flexible for in progress

* feat: make playwright report name more precise
  • Loading branch information
jamil314 authored Nov 22, 2024
1 parent 711ac45 commit d93dbd2
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 16 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/deploy-and-e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
echo "test_matrix=$test_dirs"
test:
needs: [deploy, discover-tests]
needs: [deploy, discover-tests, get-core-commit, get-country-config-commit]
runs-on: ubuntu-22.04
environment: ${{ github.event.inputs.environment || 'development' }}
strategy:
Expand Down Expand Up @@ -138,7 +138,11 @@ jobs:
- uses: actions/upload-artifact@v4
if: always() && steps.check-specs.outputs.has_spec_files == 'true'
with:
name: playwright-report-${{ matrix.test_dir }}
name: >-
playwright-report-
${{ github.event.inputs.core-image-tag || needs.get-core-commit.outputs.latest_commit_sha }}-
${{ github.event.inputs.countryconfig-image-tag || needs.get-country-config-commit.outputs.short_sha }}-
${{ matrix.test_dir }}
path: playwright-report/
retention-days: 30

Expand Down
11 changes: 8 additions & 3 deletions e2e/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,16 +80,21 @@ export const goToSection = async (

/*
Generates a random past date
at least 'minAge' years ago
at least 'minAge' years + 'offset' days ago
and up to an additional 'range' days earlier
*/
export const getRandomDate = (minAge: number, range: number) => {
export const getRandomDate = (
minAge: number,
range: number,
offset: number = 0
) => {
const randomDate = new Date()
randomDate.setDate(
new Date().getDate() -
Math.random() * range -
minAge * 365 -
(minAge + 3) / 4
(minAge + 3) / 4 -
offset
)
const [yyyy, mm, dd] = randomDate.toISOString().split('T')[0].split('-')
return { dd, mm, yyyy }
Expand Down
6 changes: 3 additions & 3 deletions e2e/testcases/birth/1-birth-event-declaration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,7 @@ test.describe('1. Birth event declaration', () => {
* - find the declared birth event record on this page list with saved data
*/
await expect(page.locator('#content-name')).toHaveText('In progress')
await expect(page.getByText('0 seconds ago')).toBeVisible()
await expect(page.getByText(/seconds ago/)).toBeVisible()
})
})
})
Expand Down Expand Up @@ -491,7 +491,7 @@ test.describe('1. Birth event declaration', () => {
await expect(
page.locator('#content-name', { hasText: 'In progress' })
).toBeVisible()
await expect(page.getByText('0 seconds ago')).toBeHidden()
await expect(page.getByText(/seconds ago/)).toBeHidden()
})
})

Expand Down Expand Up @@ -560,7 +560,7 @@ test.describe('1. Birth event declaration', () => {
await expect(
page.locator('#content-name', { hasText: 'In progress' })
).toBeVisible()
await expect(page.getByText('0 seconds ago')).toBeHidden()
await expect(page.getByText(/seconds ago/)).toBeHidden()
})
})

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { expect, test, type Page } from '@playwright/test'
import {
assignRecord,
// assignRecord,
createPIN,
expectOutboxToBeEmpty,
formatDateTo_ddMMMMyyyy,
Expand Down
6 changes: 3 additions & 3 deletions e2e/testcases/death/1-death-event-declaration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,7 @@ test.describe('1. Death event declaration', () => {
* - find the declared death event record on this page list with saved data
*/
await expect(page.locator('#content-name')).toHaveText('In progress')
await expect(page.getByText('0 seconds ago')).toBeVisible()
await expect(page.getByText(/seconds ago/)).toBeVisible()
})
})
})
Expand Down Expand Up @@ -471,7 +471,7 @@ test.describe('1. Death event declaration', () => {
await expect(
page.locator('#content-name', { hasText: 'In progress' })
).toBeVisible()
await expect(page.getByText('0 seconds ago')).toBeHidden()
await expect(page.getByText(/seconds ago/)).toBeHidden()
})
})

Expand Down Expand Up @@ -540,7 +540,7 @@ test.describe('1. Death event declaration', () => {
await expect(
page.locator('#content-name', { hasText: 'In progress' })
).toBeVisible()
await expect(page.getByText('0 seconds ago')).toBeHidden()
await expect(page.getByText(/seconds ago/)).toBeHidden()
})
})

Expand Down
4 changes: 2 additions & 2 deletions e2e/testcases/death/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ const declaration = {
},
event: {
manner: 'Natural causes',
date: getRandomDate(0, 20),
date: getRandomDate(0, 20, 20),
cause: {
established: true,
source: 'Physician'
Expand All @@ -73,7 +73,7 @@ const declaration = {
firstNames: faker.name.firstName('female'),
familyName: faker.name.lastName('female')
},
birthDate: getRandomDate(50, 200),
birthDate: getRandomDate(50, 200, 200),
nationality: 'Farajaland',
identifier: {
id: faker.random.numeric(10),
Expand Down
4 changes: 2 additions & 2 deletions playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ export default defineConfig({
// baseURL: 'http://127.0.0.1:3000',
/* Capture screenshot on failure */
screenshot: 'only-on-failure',
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry'
/* Collect trace when the test failed. See https://playwright.dev/docs/trace-viewer */
trace: 'retain-on-failure'
},

/* Configure projects for major browsers */
Expand Down

0 comments on commit d93dbd2

Please sign in to comment.