Skip to content

Commit

Permalink
opsBOModules : Add logout to actions
Browse files Browse the repository at this point in the history
  • Loading branch information
Progi1984 committed Nov 8, 2024
1 parent cae0950 commit 7c16994
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 10 deletions.
1 change: 1 addition & 0 deletions src/interfaces/BO/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export interface BOBasePagePageInterface extends CommonPageInterface {
clickOnNotificationsTab(page: Page, tabName: string): Promise<void>;
clickSubMenu(page: Page, parentSelector: string): Promise<void>;
closeAlertBlock(page: Page): Promise<void>;
closeGrowlMessage(page: Page): Promise<void>;
closeHelpSideBar(page: Page): Promise<boolean>;
closeSfToolBar(page: Frame | Page): Promise<void>;
getAlertDangerBlockParagraphContent(page: Page): Promise<string>;
Expand Down
34 changes: 34 additions & 0 deletions src/ops/BO/modules/moduleManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> {
test.setTimeout(60000);

await test.step('Reset module: should login in BO', async () => {
await utilsTest.addContextItem(test.info(), 'testIdentifier', 'loginBO', baseContext);

Expand Down Expand Up @@ -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);
});
},

/**
Expand All @@ -70,6 +81,8 @@ export default {
useVersion: boolean|string = true,
baseContext: string = 'commonTests-installModule',
): Promise<void> {
test.setTimeout(60000);

await test.step('Install module: should login in BO', async () => {
await utilsTest.addContextItem(test.info(), 'testIdentifier', 'loginBO', baseContext);

Expand Down Expand Up @@ -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);
});
},

/**
Expand All @@ -140,6 +162,8 @@ export default {
* @param baseContext {string}
*/
async uninstallModule(page: Page, module: FakerModule, baseContext: string = 'commonTests-uninstallModule'): Promise<void> {
test.setTimeout(60000);

await test.step('Uninstall module: should login in BO', async () => {
await utilsTest.addContextItem(test.info(), 'testIdentifier', 'loginBO', baseContext);

Expand Down Expand Up @@ -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);
});
},
};
3 changes: 2 additions & 1 deletion src/pages/BO/BOBasePage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

/**
Expand Down
46 changes: 37 additions & 9 deletions src/utils/file.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import fs from 'fs';
import path from 'path';
import http from 'http';
import https from 'https';
import XLSX from 'xlsx';

Expand Down Expand Up @@ -179,6 +180,7 @@ export default {

return imageNumber;
},

/**
* Generate report filename
* @return {Promise<string>}
Expand All @@ -192,6 +194,7 @@ export default {
curDate.getMinutes()}-${
curDate.getSeconds()}`;
},

/**
* Create directory if not exist
* @param path {string} Path of the directory to create
Expand All @@ -200,6 +203,7 @@ export default {
async createDirectory(path: string): Promise<void> {
if (!fs.existsSync(path)) await fs.mkdirSync(path);
},

/**
* Create file with content
* @param path {string} Path of the directory where to create
Expand All @@ -214,6 +218,7 @@ export default {
}
});
},

/**
* Check text in file
* @param filePath {string|null} Filepath to check
Expand Down Expand Up @@ -358,16 +363,38 @@ export default {
*/
async downloadFile(url: string, path: string): Promise<void> {
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) {
Expand All @@ -393,6 +420,7 @@ export default {

response.pipe(fileWriter);
});
}
});
},

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ class ModuleManagerPage extends BOBasePage implements ModuleManagerPageInterface
*/
async searchModule(page: Page, module: FakerModule): Promise<boolean> {
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();

Expand Down

0 comments on commit 7c16994

Please sign in to comment.