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 12, 2024
1 parent 6a398bb commit 6b392c6
Show file tree
Hide file tree
Showing 11 changed files with 7,456 additions and 24,210 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
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,15 @@
"storybook": "pnpm -F go-ui-storybook storybook",
"build-storybook": "pnpm -F go-ui-storybook build-storybook",
"chromatic": "pnpm -F go-ui-storybook chromatic",
"test:e2e": "pnpm -F e2e-tests playwright test"
"test:e2e": "pnpm -F e2e-tests test"
},
"devDependencies": {
"knip": "^5.36.3"
},
"engines": {
"node": "20",
"pnpm": "8.6.0"
},
"packageManager": "pnpm@8.6.0+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=
11 changes: 2 additions & 9 deletions packages/e2e-tests/playwright.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'dotenv/config';
require('dotenv').config();

/**
* See https://playwright.dev/docs/test-configuration.
* See https://playwright.dev/docs/test-configuration
*/
export default defineConfig({
testDir: './tests',
Expand All @@ -22,7 +22,7 @@ export default defineConfig({
workers: process.env.CI ? 1 : undefined,
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
reporter: 'html',
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions */
use: {
/* Base URL to use in actions like `await page.goto('/')`. */
baseURL: process.env.PLAYWRIGHT_APP_BASE_URL,
Expand Down Expand Up @@ -93,11 +93,4 @@ export default defineConfig({
dependencies: ['setup'],
},
],

/* Run your local dev server before starting the tests */
// webServer: {
// command: 'npm run start',
// url: 'http://127.0.0.1:3000',
// reuseExistingServer: !process.env.CI,
// },
});
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 6b392c6

Please sign in to comment.