update readme examples

This commit is contained in:
mildred 2024-03-13 12:59:57 +01:00
parent ae6524bd4c
commit bbd08dffb6
2 changed files with 13 additions and 12 deletions

View File

@ -81,16 +81,17 @@ An example of a simple test might look like this:
```typescript
test('Successful login as user', async ({ page }) => {
await loginAsUser(page, USER1_EMAIL, URL_IDHUB);
await expect.soft(page).toHaveTitle('Dashboard IdHub');
await expect(page).toHaveTitle('Dashboard IdHub');
})
```
The 'loginAs<User>' function, is defined in `steps.ts` as follow:
```typescript
export async function loginAsUser(page: Page, userEmail: string, url: string) {
try {
const loginPage = new LogInPage(page);
const dataProtectionPage = new DataProtectionPage(page);
await loginPage.visit(url);
await loginPage.login(userEmail, USER_K);
@ -98,10 +99,10 @@ export async function loginAsUser(page: Page, userEmail: string, url: string) {
if (currentTitle === 'Data Protection IdHub') {
// Code to accept terms and conditions
await page.click('#id_accept_privacy');
await page.click('#id_accept_legal');
await page.click('#id_accept_cookies');
await page.click('a[type="button"]');
await dataProtectionPage.checkAcceptPrivacyCheckBox();
await dataProtectionPage.checkAcceptCookiesCheckBox();
await dataProtectionPage.checkAcceptLegalCheckBox();
await dataProtectionPage.clickConfirmButton();
}
await expect(page).toHaveTitle('Dashboard IdHub');
} catch (error) {
@ -110,7 +111,7 @@ export async function loginAsUser(page: Page, userEmail: string, url: string) {
}
}
```
The 'loginAs<User>' function in `steps.ts` use the 'LoginPage' page object, where are defined all the user related actions (e.g., visit, login, etc.).
The 'loginAs<User>' function in `steps.ts` use the 'LoginPage' page object, where are defined all the user related actions (e.g., visit, login, etc.) and the 'DataProtectionPage' page object where the interactions to accept or deny the data protection options are defined.
## Project Directory Structure
@ -163,6 +164,7 @@ end2end-tests:
```
**Adding reporting**: Uploads the `playwright-report/` directory as an artifact named `playwright-report`. This step always runs, even if previous steps fail, and the artifact is retained for 30 days before automatic deletion.
```yaml
- uses: actions/upload-artifact@v3
if: always()
with:
@ -170,6 +172,6 @@ end2end-tests:
path: playwright-report/
retention-days: 30
```

View File

@ -16,7 +16,7 @@ test.describe('Admin login functionality', () => {
test('Navigate to Forgot password page from login page', async ({ page }) => {
const loginPage = new LogInPage(page)
await loginPage.visitForgotPassword(URL_PASS_RESET)
await expect.soft(page).toHaveTitle('Password reset IdHub');
await expect(page).toHaveTitle('Password reset IdHub');
})
})
@ -24,14 +24,13 @@ test.describe('Admin login functionality', () => {
test.describe('User login functionality', () => {
test('Successful login as user', async ({ page }) => {
await loginAsUser(page, USER1_EMAIL, URL_IDHUB);
await expect.soft(page).toHaveTitle('Dashboard IdHub');
//TODO: check email at the right corner
await expect(page).toHaveTitle('Dashboard IdHub');
})
test('Unsuccessful login as user', async ({ page }) => {
const loginPage = new LogInPage(page)
await loginPage.visit(URL_IDHUB);
await loginPage.login(USER1_EMAIL, KO_USER_K)
await expect.soft(loginPage.errorMessageIsValid()).toBeTruthy();
await expect(loginPage.errorMessageIsValid()).toBeTruthy();
})
})