From 7c16994231ae0ca50a09ece43e3006eabeedab5d Mon Sep 17 00:00:00 2001 From: Progi1984 Date: Fri, 27 Sep 2024 17:30:50 +0200 Subject: [PATCH] `opsBOModules` : Add logout to actions --- src/interfaces/BO/index.ts | 1 + src/ops/BO/modules/moduleManager.ts | 34 ++++++++++++++ src/pages/BO/BOBasePage.ts | 3 +- src/utils/file.ts | 46 +++++++++++++++---- .../pages/BO/modules/moduleManager/index.ts | 1 + 5 files changed, 75 insertions(+), 10 deletions(-) diff --git a/src/interfaces/BO/index.ts b/src/interfaces/BO/index.ts index 9d7a36eb..39527264 100644 --- a/src/interfaces/BO/index.ts +++ b/src/interfaces/BO/index.ts @@ -83,6 +83,7 @@ export interface BOBasePagePageInterface extends CommonPageInterface { clickOnNotificationsTab(page: Page, tabName: string): Promise; clickSubMenu(page: Page, parentSelector: string): Promise; closeAlertBlock(page: Page): Promise; + closeGrowlMessage(page: Page): Promise; closeHelpSideBar(page: Page): Promise; closeSfToolBar(page: Frame | Page): Promise; getAlertDangerBlockParagraphContent(page: Page): Promise; diff --git a/src/ops/BO/modules/moduleManager.ts b/src/ops/BO/modules/moduleManager.ts index 345325cc..1f02ae5a 100644 --- a/src/ops/BO/modules/moduleManager.ts +++ b/src/ops/BO/modules/moduleManager.ts @@ -14,6 +14,8 @@ export default { * @param baseContext {string} String to identify the test */ async resetModule(page: Page, module: FakerModule, baseContext: string = 'commonTests-resetModule'): Promise { + test.setTimeout(60000); + await test.step('Reset module: should login in BO', async () => { await utilsTest.addContextItem(test.info(), 'testIdentifier', 'loginBO', baseContext); @@ -51,6 +53,15 @@ export default { const successMessage = await boModuleManagerPage.setActionInModule(page, module, 'reset'); expect(successMessage).toEqual(boModuleManagerPage.resetModuleSuccessMessage(module.tag)); }); + + await test.step('Reset module: should logout', async () => { + await utilsTest.addContextItem(test.info(), 'testIdentifier', 'logout', baseContext); + + await boModuleManagerPage.logoutBO(page); + + const pageTitle = await boLoginPage.getPageTitle(page); + expect(pageTitle).toContain(boLoginPage.pageTitle); + }); }, /** @@ -70,6 +81,8 @@ export default { useVersion: boolean|string = true, baseContext: string = 'commonTests-installModule', ): Promise { + test.setTimeout(60000); + await test.step('Install module: should login in BO', async () => { await utilsTest.addContextItem(test.info(), 'testIdentifier', 'loginBO', baseContext); @@ -131,6 +144,15 @@ export default { const isModuleVisible = await boModuleManagerPage.searchModule(page, module); expect(isModuleVisible).toBeTruthy(); }); + + await test.step('Install module: should logout', async () => { + await utilsTest.addContextItem(test.info(), 'testIdentifier', 'logout', baseContext); + + await boModuleManagerPage.logoutBO(page); + + const pageTitle = await boLoginPage.getPageTitle(page); + expect(pageTitle).toContain(boLoginPage.pageTitle); + }); }, /** @@ -140,6 +162,8 @@ export default { * @param baseContext {string} */ async uninstallModule(page: Page, module: FakerModule, baseContext: string = 'commonTests-uninstallModule'): Promise { + test.setTimeout(60000); + await test.step('Uninstall module: should login in BO', async () => { await utilsTest.addContextItem(test.info(), 'testIdentifier', 'loginBO', baseContext); @@ -177,5 +201,15 @@ export default { const successMessage = await boModuleManagerPage.setActionInModule(page, module, 'uninstall', false, true); expect(successMessage).toEqual(boModuleManagerPage.uninstallModuleSuccessMessage(module.tag)); }); + + await test.step('Uninstall module: should logout', async () => { + await utilsTest.addContextItem(test.info(), 'testIdentifier', 'logout', baseContext); + + await boModuleManagerPage.reloadPage(page); + await boModuleManagerPage.logoutBO(page); + + const pageTitle = await boLoginPage.getPageTitle(page); + expect(pageTitle).toContain(boLoginPage.pageTitle); + }); }, }; diff --git a/src/pages/BO/BOBasePage.ts b/src/pages/BO/BOBasePage.ts index 79106a0c..cbd0b63e 100644 --- a/src/pages/BO/BOBasePage.ts +++ b/src/pages/BO/BOBasePage.ts @@ -979,7 +979,8 @@ export default class BOBasePage extends CommonPage implements BOBasePagePageInte await page.locator(this.userProfileIconNonMigratedPages).click(); } await this.waitForVisibleSelector(page, this.userProfileLogoutLink); - await this.clickAndWaitForURL(page, this.userProfileLogoutLink); + await page.locator(this.userProfileLogoutLink).first().click(); + await page.waitForURL('**/login'); } /** diff --git a/src/utils/file.ts b/src/utils/file.ts index 82045efe..8fcc3e5b 100644 --- a/src/utils/file.ts +++ b/src/utils/file.ts @@ -1,5 +1,6 @@ import fs from 'fs'; import path from 'path'; +import http from 'http'; import https from 'https'; import XLSX from 'xlsx'; @@ -179,6 +180,7 @@ export default { return imageNumber; }, + /** * Generate report filename * @return {Promise} @@ -192,6 +194,7 @@ export default { curDate.getMinutes()}-${ curDate.getSeconds()}`; }, + /** * Create directory if not exist * @param path {string} Path of the directory to create @@ -200,6 +203,7 @@ export default { async createDirectory(path: string): Promise { if (!fs.existsSync(path)) await fs.mkdirSync(path); }, + /** * Create file with content * @param path {string} Path of the directory where to create @@ -214,6 +218,7 @@ export default { } }); }, + /** * Check text in file * @param filePath {string|null} Filepath to check @@ -358,16 +363,38 @@ export default { */ async downloadFile(url: string, path: string): Promise { await new Promise((resolve, reject): void => { - const httpsAgent: https.Agent = new https.Agent({ - rejectUnauthorized: false, - }); + if (url.startsWith('http://')) { + http.get(url, (response: http.IncomingMessage): void => { + const code = response.statusCode ?? 0; + + if (code >= 400) { + reject(new Error(response.statusMessage)); + return; + } - https.get( - url, - { - agent: httpsAgent, - }, - (response): void => { + // Handle redirects + if (code > 300 && code < 400 && !!response.headers.location) { + resolve( + this.downloadFile(response.headers.location, path), + ); + return; + } + + // Save the file to disk + const fileWriter: fs.WriteStream = fs + .createWriteStream(path) + .on('finish', (): void => { + fileWriter.close(); + resolve({}); + }); + + response.pipe(fileWriter); + }); + } else { + const agent: https.Agent = new https.Agent({ + rejectUnauthorized: false, + }); + https.get(url, {agent}, (response: http.IncomingMessage): void => { const code = response.statusCode ?? 0; if (code >= 400) { @@ -393,6 +420,7 @@ export default { response.pipe(fileWriter); }); + } }); }, diff --git a/src/versions/develop/pages/BO/modules/moduleManager/index.ts b/src/versions/develop/pages/BO/modules/moduleManager/index.ts index 751475c7..db5f92d4 100644 --- a/src/versions/develop/pages/BO/modules/moduleManager/index.ts +++ b/src/versions/develop/pages/BO/modules/moduleManager/index.ts @@ -250,6 +250,7 @@ class ModuleManagerPage extends BOBasePage implements ModuleManagerPageInterface */ async searchModule(page: Page, module: FakerModule): Promise { await this.reloadPage(page); + await this.elementVisible(page, this.searchModuleTagInput, 60000); await page.locator(this.searchModuleTagInput).fill(module.tag); await page.locator(this.searchModuleButton).click();