diff --git a/src/constants/env_constants.ts b/src/constants/env_constants.ts index 9904f31..c294edb 100644 --- a/src/constants/env_constants.ts +++ b/src/constants/env_constants.ts @@ -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" diff --git a/src/page-objects/AD_AddMembershipPage.ts b/src/page-objects/AD_AddMembershipPage.ts index 3f30a9a..151456e 100644 --- a/src/page-objects/AD_AddMembershipPage.ts +++ b/src/page-objects/AD_AddMembershipPage.ts @@ -131,22 +131,18 @@ export class AddMembershipPage { async alertUserCreationMessageIsValid(): Promise { - 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; } - } diff --git a/src/page-objects/AD_ImportDataPage.ts b/src/page-objects/AD_ImportDataPage.ts index 4341032..5a788d6 100644 --- a/src/page-objects/AD_ImportDataPage.ts +++ b/src/page-objects/AD_ImportDataPage.ts @@ -102,20 +102,18 @@ export class ImportDataPage { } async alertFileImportedUnsuccessfully(expectedMessage: string): Promise { + 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; } } diff --git a/src/page-objects/AD_ViewImportedDataPage.ts b/src/page-objects/AD_ViewImportedDataPage.ts index 27fd43f..50a8737 100644 --- a/src/page-objects/AD_ViewImportedDataPage.ts +++ b/src/page-objects/AD_ViewImportedDataPage.ts @@ -107,7 +107,7 @@ export class ViewImportedDataPage { throw error; } } - + async isFileSuccessfullyLoaded(fileName: string): Promise { try { const row = this.page.locator(`tr:has-text('${fileName}')`); @@ -134,24 +134,17 @@ export class ViewImportedDataPage { async alertFileImportedSuccessfully(): Promise { 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 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; - 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; - } - } - - 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; } } - } \ No newline at end of file diff --git a/src/page-objects/COMM_LoginPage.ts b/src/page-objects/COMM_LoginPage.ts index d386929..c61774e 100644 --- a/src/page-objects/COMM_LoginPage.ts +++ b/src/page-objects/COMM_LoginPage.ts @@ -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 { + 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; + throw error; } - } -} + } +} \ No newline at end of file diff --git a/src/steps.ts b/src/steps.ts index 8a9006c..210bf34 100644 --- a/src/steps.ts +++ b/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,34 +16,40 @@ 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'); - + } catch (error) { console.error(`Failed to login as admin: `); throw error; diff --git a/tests/00-COMM-loginFunctionality.spec.ts b/tests/00-COMM-loginFunctionality.spec.ts index 7e080fc..8d5d101 100644 --- a/tests/00-COMM-loginFunctionality.spec.ts +++ b/tests/00-COMM-loginFunctionality.spec.ts @@ -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) diff --git a/vc_excel/financial-vulnerability-alienUser-with-user5Data.xlsx b/vc_excel/financial-vulnerability-alienUser-with-user5Data.xlsx deleted file mode 100644 index 88909c1..0000000 Binary files a/vc_excel/financial-vulnerability-alienUser-with-user5Data.xlsx and /dev/null differ