Fix login flaky tests
This commit is contained in:
parent
31915928f5
commit
e0771c1f3f
|
@ -1,9 +1,10 @@
|
|||
/*Login*/
|
||||
export const ENCRYPTION_KEY = "1234"
|
||||
export const ADMIN_EMAIL = "idhub_admin@pangea.org"
|
||||
export const ADMIN_K = "1234"
|
||||
export const KO_ADMIN_K = "876"
|
||||
export const URL_IDHUB = "https://idhub1-autotest.demo.pangea.org"
|
||||
//export const URL_IDHUB = "https://idhub-nightly.demo.pangea.org"
|
||||
//export const URL_IDHUB = "https://idhub1-nightly.demo.pangea.org"
|
||||
|
||||
export const USER1_EMAIL = "user1@example.org"
|
||||
export const USER2_EMAIL = "user2@example.org"
|
||||
|
|
|
@ -131,22 +131,18 @@ export class AddMembershipPage {
|
|||
|
||||
async alertUserCreationMessageIsValid(): Promise<boolean> {
|
||||
|
||||
await this.page.waitForSelector('.alert.alert-success.alert-dismissible');
|
||||
const element = await this.page.$('.alert.alert-success.alert-dismissible');
|
||||
try {
|
||||
await this.page.locator('.alert.alert-success.alert-dismissible').waitFor({ state: 'visible', timeout: 5000 });
|
||||
// If the success message is found and visible, retrieve its text content
|
||||
const message = await this.page.locator('.alert.alert-success.alert-dismissible').textContent();
|
||||
|
||||
if (element !== null) {
|
||||
const isVisible = await element.isVisible();
|
||||
if (isVisible) {
|
||||
const text = await element.innerText();
|
||||
console.log(text);
|
||||
if (text === ALERT_USER_CREATED_SUCESSFULLY_MESSAGE) {
|
||||
return true;
|
||||
// Compare the retrieved text with the expected error message
|
||||
return message?.trim() === ALERT_USER_CREATED_SUCESSFULLY_MESSAGE;
|
||||
|
||||
} catch (error) {
|
||||
console.error('Failed to check success message:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -102,20 +102,18 @@ export class ImportDataPage {
|
|||
}
|
||||
|
||||
async alertFileImportedUnsuccessfully(expectedMessage: string): Promise<boolean> {
|
||||
|
||||
try {
|
||||
const element = this.page.locator('.alert.alert-danger.alert-dismissible');
|
||||
if (element) {
|
||||
const isVisible = await element.isVisible();
|
||||
if (isVisible) {
|
||||
const text = await element.innerText();
|
||||
console.log(text);
|
||||
expect(text).toBe(expectedMessage);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
await this.page.locator('.alert.alert-danger.alert-dismissible').waitFor({ state: 'visible', timeout: 5000 });
|
||||
|
||||
// If the success message is found and visible, retrieve its text content
|
||||
const message = await this.page.locator('.alert.alert-danger.alert-dismissible').textContent();
|
||||
|
||||
// Compare the retrieved text with the expected error message
|
||||
return message?.trim() === expectedMessage;
|
||||
|
||||
} catch (error) {
|
||||
console.error("Failed to check for unsuccessful file import alert:", error);
|
||||
console.error('Failed to check for unsuccessful file import alert:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -134,24 +134,17 @@ export class ViewImportedDataPage {
|
|||
|
||||
async alertFileImportedSuccessfully(): Promise<boolean> {
|
||||
try {
|
||||
await this.page.waitForSelector('.alert.alert-success.alert-dismissible');
|
||||
const element = await this.page.$('.alert.alert-success.alert-dismissible');
|
||||
await this.page.locator('.alert.alert-success.alert-dismissible').waitFor({ state: 'visible', timeout: 5000 });
|
||||
|
||||
if (element !== null) {
|
||||
const isVisible = await element.isVisible();
|
||||
if (isVisible) {
|
||||
const text = await element.innerText();
|
||||
console.log(text);
|
||||
expect(text).toBe(ALERT_FILE_IMPORTED_SUCCESSFULLY);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
// If the success message is found and visible, retrieve its text content
|
||||
const message = await this.page.locator('.alert.alert-success.alert-dismissible').textContent();
|
||||
|
||||
// Compare the retrieved text with the expected error message
|
||||
return message?.trim() === ALERT_FILE_IMPORTED_SUCCESSFULLY;
|
||||
|
||||
return false;
|
||||
} catch (error) {
|
||||
console.error("Failed to check for successful file import alert:", error);
|
||||
console.error('Failed to check for successful file import alert:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
import { type Page, type Locator } from '@playwright/test';
|
||||
import { type Page, type Locator, expect } from '@playwright/test';
|
||||
import { ERROR_INCORRECT_EMAIL_PASSWORD } from '../constants/constants';
|
||||
|
||||
export class LogInPage {
|
||||
|
@ -41,18 +41,25 @@ export class LogInPage {
|
|||
}
|
||||
}
|
||||
|
||||
async errorMessageIsValid(): Promise<boolean> {
|
||||
async errorMessageIsValid() {
|
||||
|
||||
try {
|
||||
const isVisible = await this.page.locator('.well.well-small.text-error').isVisible();
|
||||
if (!isVisible) {
|
||||
return false;
|
||||
|
||||
try {
|
||||
await this.page.locator('.well.well-small.text-error').waitFor({ state: 'visible', timeout: 5000 });
|
||||
} catch (error) {
|
||||
console.error('Error message not found:', error);
|
||||
return false; // Return false if the error message is not found
|
||||
}
|
||||
// If the error message is found and visible, retrieve its text content
|
||||
const errorText = await this.page.locator('.well.well-small.text-error').textContent();
|
||||
return errorText === ERROR_INCORRECT_EMAIL_PASSWORD;
|
||||
|
||||
// Compare the retrieved text with the expected error message
|
||||
return errorText?.trim() === ERROR_INCORRECT_EMAIL_PASSWORD;
|
||||
} catch (error) {
|
||||
console.error('Failed to check error message:', error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
22
src/steps.ts
22
src/steps.ts
|
@ -6,7 +6,7 @@ import { CREDENTIAL_TYPE_DATASTORE_UNDEFINED, CREDENTIAL_TYPES_DATA_STORE } from
|
|||
import { FinancialVulnerabilityCredential_fields } from './interfaces/credential_interfaces'
|
||||
import { CREDENTIAL_TYPES_FIELDS_LIST, CREDENTIAL_TYPES_REQUIRED_FIELDS_LIST } from './constants/credential_fields'
|
||||
import { LogInPage } from './page-objects/COMM_LoginPage'
|
||||
import { ADMIN_EMAIL, ADMIN_K, USER_K } from './constants/env_constants'
|
||||
import { ADMIN_EMAIL, ADMIN_K, ENCRYPTION_KEY, USER_K } from './constants/env_constants'
|
||||
import { LeftMenuAdminPage } from './page-objects/AD_LeftMenuAdminPage'
|
||||
import { LeftMenuUserPage } from './page-objects/US_LeftMenuUserPage'
|
||||
import { TemplatesPage } from './page-objects/AD_TemplatesPage'
|
||||
|
@ -16,31 +16,37 @@ import { UserPersonalInformationPage } from './page-objects/AD_UserPersonalInfor
|
|||
import { ImportTemplatePage } from './page-objects/AD_ImportTemplatePage'
|
||||
import { ViewImportedDataPage } from './page-objects/AD_ViewImportedDataPage'
|
||||
import { User } from './interfaces/User'
|
||||
import { EncryptionKeyPage } from './page-objects/AD_EncryptionKeyPage'
|
||||
import { DataProtectionPage } from './page-objects/COMM_DataProtectionPage'
|
||||
|
||||
|
||||
export async function loginAsAdmin(page: Page, url: string) {
|
||||
try {
|
||||
const loginPage = new LogInPage(page);
|
||||
const encryptionKeyPage = new EncryptionKeyPage(page);
|
||||
const dataProtectionPage = new DataProtectionPage(page);
|
||||
|
||||
await loginPage.visit(url);
|
||||
await loginPage.login(ADMIN_EMAIL, ADMIN_K);
|
||||
|
||||
let currentTitle = await page.title();
|
||||
console.log("current title: ", currentTitle);
|
||||
|
||||
if (currentTitle === 'Encryption Key – IdHub') {
|
||||
//code to set Encription Key
|
||||
page.getByPlaceholder('Key for encrypt the secrets').click();
|
||||
await page.getByPlaceholder('Key for encrypt the secrets').fill('1234');
|
||||
await page.getByRole('button', { name: 'Save' }).click();
|
||||
await encryptionKeyPage.enterKey(ENCRYPTION_KEY);
|
||||
await encryptionKeyPage.clickSaveButton();
|
||||
|
||||
await expect(page).toHaveTitle('Data protection – IdHub');
|
||||
currentTitle = await page.title();
|
||||
}
|
||||
|
||||
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');
|
||||
|
||||
|
|
|
@ -6,13 +6,12 @@ import { ADMIN_EMAIL, KO_ADMIN_K, KO_USER_K, URL_IDHUB, URL_PASS_RESET, USER1_EM
|
|||
test.describe('Admin login functionality', () => {
|
||||
test('Successful login as admin', async ({ page }) => {
|
||||
await loginAsAdmin(page, URL_IDHUB);
|
||||
await expect.soft(page).toHaveTitle('Dashboard – IdHub');
|
||||
})
|
||||
test('Unsuccessful login as admin', async ({ page }) => {
|
||||
const loginPage = new LogInPage(page)
|
||||
await loginPage.visit(URL_IDHUB);
|
||||
await loginPage.login(ADMIN_EMAIL, KO_ADMIN_K)
|
||||
expect.soft(loginPage.errorMessageIsValid()).toBeTruthy();
|
||||
expect(loginPage.errorMessageIsValid()).toBeTruthy();
|
||||
})
|
||||
test('Navigate to Forgot password page from login page', async ({ page }) => {
|
||||
const loginPage = new LogInPage(page)
|
||||
|
|
Binary file not shown.
Reference in New Issue