Skip to content

Commit

Permalink
fix: add redirecting to field report listing page in playwright tests
Browse files Browse the repository at this point in the history
  • Loading branch information
samshara committed Dec 9, 2024
1 parent 6a398bb commit a342afd
Show file tree
Hide file tree
Showing 10 changed files with 7,453 additions and 24,200 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Playwright

env:
PLAYWRIGHT_APP_BASE_URL: ${{ vars.PLAYWRIGHT_APP_BASE_URL }}
PLAYWRIGHT_USER_NAME: ${{ secrets.PLAYWRIGHT_USER_NAME }}
PLAYWRIGHT_USER_EMAIL: ${{ secrets.PLAYWRIGHT_USER_EMAIL }}
PLAYWRIGHT_USER_PASSWORD: ${{ secrets.PLAYWRIGHT_USER_PASSWORD }}

on:
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
"devDependencies": {
"knip": "^5.36.3"
},
"engines": {
"node": "20",
"pnpm": "8.6.0"
},
"packageManager": "[email protected]+sha1.71f9126a20cd3d00fa47c188f956918858180e54",
"pnpm": {
"patchedDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/e2e-tests/.env.example
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Base URL for the application where Playwright will run tests
PLAYWRIGHT_APP_BASE_URL=
# User name of the test user for Playwright
PLAYWRIGHT_USER_NAME=
PLAYWRIGHT_USER_EMAIL=
# Password of the test user for Playwright
PLAYWRIGHT_USER_PASSWORD=
4 changes: 2 additions & 2 deletions packages/e2e-tests/tests/auth.setup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ const authFile = 'playwright/.auth/user.json';

setup('authenticate', async ({ page }) => {
if (
process.env.PLAYWRIGHT_USER_NAME &&
process.env.PLAYWRIGHT_USER_EMAIL &&
process.env.PLAYWRIGHT_USER_PASSWORD
) {
await login(
page,
process.env.PLAYWRIGHT_USER_NAME,
process.env.PLAYWRIGHT_USER_EMAIL,
process.env.PLAYWRIGHT_USER_PASSWORD,
);
}
Expand Down
2 changes: 2 additions & 0 deletions packages/e2e-tests/tests/earlyWarning/earlyWarning.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,8 @@ test.describe('Field Report', () => {
.filter({ hasText: visibiltyOptTwo })
.click();
await page.getByRole('button', { name: 'Submit' }).click();
// Wait for redirection to field reports listing page
await page.waitForURL(/\/field-reports\/\d+/);
await expect(page.locator('h1')).toContainText(
`${newtitle} - ${title}`,
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,8 @@ test.describe('Field report flow', async () => {
.filter({ hasText: visibiltyOptTwo })
.click();
await page.getByRole('button', { name: 'Submit' }).click();
await expect(page.locator('body')).toContainText(
'Field report updated, redirecting...',
);
// Wait for redirection to field reports listing page
await page.waitForURL(/\/field-reports\/\d+/);
// Title Assertion
await expect(page.locator('h1')).toContainText(
`${newtitle} - ${title}`,
Expand Down
5 changes: 2 additions & 3 deletions packages/e2e-tests/tests/field-report/fieldReport.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,9 +266,8 @@ test.describe('Field Report', () => {
.filter({ hasText: visibiltyOptTwo })
.click();
await page.getByRole('button', { name: 'Submit' }).click();
await expect(page.locator('body')).toContainText(
'Field report updated, redirecting...',
);
// Wait for redirection to field reports listing page
await page.waitForURL(/\/field-reports\/\d+/);
// Title Assertion
await expect(page.locator('h1')).toContainText(
`${newtitle} - ${title}`,
Expand Down
9 changes: 4 additions & 5 deletions packages/e2e-tests/tests/loginLogout.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { login } from '#utils/auth';
test('should login', async ({ page }) => {
await login(
page,
process.env.PLAYWRIGHT_USER_NAME,
process.env.PLAYWRIGHT_USER_EMAIL,
process.env.PLAYWRIGHT_USER_PASSWORD,
);
await page.waitForURL('/');
Expand All @@ -15,13 +15,12 @@ test('should login', async ({ page }) => {
test('should logout', async ({ page }) => {
await login(
page,
process.env.PLAYWRIGHT_USER_NAME,
process.env.PLAYWRIGHT_USER_EMAIL,
process.env.PLAYWRIGHT_USER_PASSWORD,
);
await page.waitForURL('/');
await page
.getByRole('button', { name: process.env.PLAYWRIGHT_USER_NAME })
.click();
const name = process.env.PLAYWRIGHT_USER_EMAIL.match(/^[^@]+(?=@)/);
await page.getByRole('button', { name: name[0] }).click();
await page.getByRole('button', { name: 'Logout' }).click();
await page.getByRole('button', { name: 'Ok' }).click();
await expect(page.getByRole('navigation')).toContainText('Login');
Expand Down
Loading

0 comments on commit a342afd

Please sign in to comment.