-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fix Playwright config * Add docs for E2E testing
- Loading branch information
Showing
146 changed files
with
485 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { Page, expect } from '@playwright/test'; | ||
import { Persona } from './sign-in.page'; | ||
|
||
type Details = { | ||
message?: string; // note: there's no message for spontaneous feedback | ||
positive: string; | ||
negative: string; | ||
comment: string; | ||
}; | ||
|
||
export class ManagerPage { | ||
constructor(private page: Page) {} | ||
|
||
async goto() { | ||
await this.page.goto('/fr/manager'); | ||
} | ||
|
||
async selectManaged(persona: Persona) { | ||
await this.page.getByLabel('Collaborateur').click(); | ||
await this.page.getByRole('option', { name: persona }).click(); | ||
} | ||
|
||
async findGiverDetailsLink(persona: Persona) { | ||
// Wait until the the `<table>` is rendered | ||
await this.page.locator('tbody').waitFor(); | ||
|
||
return this.page | ||
.locator('tbody > tr', { has: this.page.getByRole('cell', { name: persona }) }) | ||
.getByLabel('Consulter'); // note: the label can be 'Consulter la demande' or 'Consulter le feedZback' | ||
} | ||
|
||
async matchPendingFeedback(giver: Persona, receiver: Persona, message: string) { | ||
await this.page.waitForURL('/fr/manager/document/**'); | ||
|
||
await expect(this.page.getByRole('heading', { name: 'Demande de feedZback partagé' })).toBeVisible(); | ||
|
||
await expect(this.page.getByText(giver)).toBeVisible(); | ||
await expect(this.page.getByText(receiver)).toBeVisible(); | ||
|
||
if (message) { | ||
await expect(this.page.getByText(message)).toBeVisible(); | ||
} | ||
} | ||
|
||
async matchDoneFeedback(giver: Persona, receiver: Persona, details: Details) { | ||
await this.page.waitForURL('/fr/manager/document/**'); | ||
|
||
await expect(this.page.getByRole('heading', { name: 'FeedZback partagé' })).toBeVisible(); | ||
|
||
await expect(this.page.getByText(giver)).toBeVisible(); | ||
await expect(this.page.getByText(receiver)).toBeVisible(); | ||
|
||
if (details.message) { | ||
await expect(this.page.getByText(details.message)).toBeVisible(); | ||
} | ||
await expect(this.page.getByText(details.positive)).toBeVisible(); | ||
await expect(this.page.getByText(details.negative)).toBeVisible(); | ||
await expect(this.page.getByText(details.comment)).toBeVisible(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import { Page } from '@playwright/test'; | ||
import { Persona } from './sign-in.page'; | ||
|
||
export class SettingsPage { | ||
constructor(private page: Page) {} | ||
|
||
async goto() { | ||
await this.page.goto('/fr/settings'); | ||
} | ||
|
||
async setManager(persona: Persona) { | ||
await this.page.getByLabel('Email de votre manager').fill(persona); | ||
await this.page.getByRole('button', { name: 'Mettre à jour' }).click(); | ||
} | ||
|
||
async gotoAndSetManager(persona: Persona) { | ||
await this.goto(); | ||
await this.setManager(persona); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# E2E testing | ||
|
||
E2E tests are performed using [Playwright](https://playwright.dev/). | ||
|
||
## NPM scripts | ||
|
||
To run the tests, open a terminal in `<rootDir>/client` directory and run the following command: | ||
|
||
```bash | ||
npm run e2e:test | ||
``` | ||
|
||
All scripts related to E2E tests start with `"e2e:*"`: | ||
|
||
```json title="<rootDir>/client/package.json" | ||
{ | ||
"scripts": { | ||
"e2e:test": "playwright test", | ||
"e2e:report": "playwright show-report", | ||
"e2e:ui": "playwright test --ui", | ||
"e2e:codegen": "playwright codegen" | ||
} | ||
} | ||
``` | ||
|
||
## Playwright configuration | ||
|
||
Here's part of the Playwright configuration: | ||
|
||
```ts title="<rootDir>/client/playwright.config.ts" | ||
import { defineConfig } from '@playwright/test'; | ||
|
||
export default defineConfig({ | ||
// Tests are located in the following directory | ||
testDir: './e2e', | ||
|
||
// Run your local dev server before starting the tests | ||
webServer: { | ||
command: 'npm run stack:e2e', | ||
port: 4200, | ||
reuseExistingServer: !process.env['CI'], | ||
}, | ||
}); | ||
``` | ||
|
||
Before starting the tests, Playwright executes the command `npm run stack:e2e` and waits for the application to be available on port `4200`. | ||
Due to the `reuseExistingServer` option (enabled for non-CI environment), the command will not be executed if the application is already available. | ||
|
||
Therefore, you can run the command `npm run stack:e2e` in one terminal, wait for the application to be available on port `4200`, and then run the command `npm run e2e:test` in another terminal. | ||
In this case, Playwright will skip the `webServer.command`, starting the tests immediately. | ||
|
||
## Running Playwright | ||
|
||
### Method 1 | ||
|
||
To have Playwright start the app and the tests, run the following command: | ||
|
||
```bash | ||
npm run e2e:test | ||
``` | ||
|
||
:::warning | ||
At the end of the tests, Playwright may not stop the `webServer` properly. | ||
If this happens, look for a "ghost" process named `java` and kill it manually. | ||
|
||
To avoid this problem, use the method 2 instead. | ||
::: | ||
|
||
### Method 2 | ||
|
||
To start the app once and then have Playwright only start the tests, run the following commands in two separate terminals: | ||
|
||
```bash | ||
npm run stack:e2e # First terminal | ||
``` | ||
|
||
```bash | ||
npm run e2e:test # Second terminal | ||
``` | ||
|
||
:::tip | ||
As an alternative to the above command in the first terminal, run `npm run stack:emulators` instead, to start the app in "watch" mode. | ||
::: |
Oops, something went wrong.