Skip to content

Commit 780f108

Browse files
committed
opsBOModules : Add logout to actions
1 parent cae0950 commit 780f108

File tree

4 files changed

+74
-10
lines changed

4 files changed

+74
-10
lines changed

src/interfaces/BO/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ export interface BOBasePagePageInterface extends CommonPageInterface {
8383
clickOnNotificationsTab(page: Page, tabName: string): Promise<void>;
8484
clickSubMenu(page: Page, parentSelector: string): Promise<void>;
8585
closeAlertBlock(page: Page): Promise<void>;
86+
closeGrowlMessage(page: Page): Promise<void>;
8687
closeHelpSideBar(page: Page): Promise<boolean>;
8788
closeSfToolBar(page: Frame | Page): Promise<void>;
8889
getAlertDangerBlockParagraphContent(page: Page): Promise<string>;

src/ops/BO/modules/moduleManager.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export default {
1414
* @param baseContext {string} String to identify the test
1515
*/
1616
async resetModule(page: Page, module: FakerModule, baseContext: string = 'commonTests-resetModule'): Promise<void> {
17+
test.setTimeout(60000);
18+
1719
await test.step('Reset module: should login in BO', async () => {
1820
await utilsTest.addContextItem(test.info(), 'testIdentifier', 'loginBO', baseContext);
1921

@@ -51,6 +53,15 @@ export default {
5153
const successMessage = await boModuleManagerPage.setActionInModule(page, module, 'reset');
5254
expect(successMessage).toEqual(boModuleManagerPage.resetModuleSuccessMessage(module.tag));
5355
});
56+
57+
await test.step('Reset module: should logout', async () => {
58+
await utilsTest.addContextItem(test.info(), 'testIdentifier', 'logout', baseContext);
59+
60+
await boModuleManagerPage.logoutBO(page);
61+
62+
const pageTitle = await boLoginPage.getPageTitle(page);
63+
expect(pageTitle).toContain(boLoginPage.pageTitle);
64+
});
5465
},
5566

5667
/**
@@ -70,6 +81,8 @@ export default {
7081
useVersion: boolean|string = true,
7182
baseContext: string = 'commonTests-installModule',
7283
): Promise<void> {
84+
test.setTimeout(60000);
85+
7386
await test.step('Install module: should login in BO', async () => {
7487
await utilsTest.addContextItem(test.info(), 'testIdentifier', 'loginBO', baseContext);
7588

@@ -131,6 +144,15 @@ export default {
131144
const isModuleVisible = await boModuleManagerPage.searchModule(page, module);
132145
expect(isModuleVisible).toBeTruthy();
133146
});
147+
148+
await test.step('Install module: should logout', async () => {
149+
await utilsTest.addContextItem(test.info(), 'testIdentifier', 'logout', baseContext);
150+
151+
await boModuleManagerPage.logoutBO(page);
152+
153+
const pageTitle = await boLoginPage.getPageTitle(page);
154+
expect(pageTitle).toContain(boLoginPage.pageTitle);
155+
});
134156
},
135157

136158
/**
@@ -140,6 +162,8 @@ export default {
140162
* @param baseContext {string}
141163
*/
142164
async uninstallModule(page: Page, module: FakerModule, baseContext: string = 'commonTests-uninstallModule'): Promise<void> {
165+
test.setTimeout(60000);
166+
143167
await test.step('Uninstall module: should login in BO', async () => {
144168
await utilsTest.addContextItem(test.info(), 'testIdentifier', 'loginBO', baseContext);
145169

@@ -177,5 +201,15 @@ export default {
177201
const successMessage = await boModuleManagerPage.setActionInModule(page, module, 'uninstall', false, true);
178202
expect(successMessage).toEqual(boModuleManagerPage.uninstallModuleSuccessMessage(module.tag));
179203
});
204+
205+
await test.step('Uninstall module: should logout', async () => {
206+
await utilsTest.addContextItem(test.info(), 'testIdentifier', 'logout', baseContext);
207+
208+
await boModuleManagerPage.reloadPage(page);
209+
await boModuleManagerPage.logoutBO(page);
210+
211+
const pageTitle = await boLoginPage.getPageTitle(page);
212+
expect(pageTitle).toContain(boLoginPage.pageTitle);
213+
});
180214
},
181215
};

src/pages/BO/BOBasePage.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -979,7 +979,8 @@ export default class BOBasePage extends CommonPage implements BOBasePagePageInte
979979
await page.locator(this.userProfileIconNonMigratedPages).click();
980980
}
981981
await this.waitForVisibleSelector(page, this.userProfileLogoutLink);
982-
await this.clickAndWaitForURL(page, this.userProfileLogoutLink);
982+
await page.locator(this.userProfileLogoutLink).first().click();
983+
await page.waitForURL('**/login');
983984
}
984985

985986
/**

src/utils/file.ts

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fs from 'fs';
22
import path from 'path';
3+
import http from 'http';
34
import https from 'https';
45
import XLSX from 'xlsx';
56

@@ -179,6 +180,7 @@ export default {
179180

180181
return imageNumber;
181182
},
183+
182184
/**
183185
* Generate report filename
184186
* @return {Promise<string>}
@@ -192,6 +194,7 @@ export default {
192194
curDate.getMinutes()}-${
193195
curDate.getSeconds()}`;
194196
},
197+
195198
/**
196199
* Create directory if not exist
197200
* @param path {string} Path of the directory to create
@@ -200,6 +203,7 @@ export default {
200203
async createDirectory(path: string): Promise<void> {
201204
if (!fs.existsSync(path)) await fs.mkdirSync(path);
202205
},
206+
203207
/**
204208
* Create file with content
205209
* @param path {string} Path of the directory where to create
@@ -214,6 +218,7 @@ export default {
214218
}
215219
});
216220
},
221+
217222
/**
218223
* Check text in file
219224
* @param filePath {string|null} Filepath to check
@@ -358,16 +363,38 @@ export default {
358363
*/
359364
async downloadFile(url: string, path: string): Promise<void> {
360365
await new Promise((resolve, reject): void => {
361-
const httpsAgent: https.Agent = new https.Agent({
362-
rejectUnauthorized: false,
363-
});
366+
if (url.startsWith('http://')) {
367+
http.get(url, (response: http.IncomingMessage): void => {
368+
const code = response.statusCode ?? 0;
369+
370+
if (code >= 400) {
371+
reject(new Error(response.statusMessage));
372+
return;
373+
}
364374

365-
https.get(
366-
url,
367-
{
368-
agent: httpsAgent,
369-
},
370-
(response): void => {
375+
// Handle redirects
376+
if (code > 300 && code < 400 && !!response.headers.location) {
377+
resolve(
378+
this.downloadFile(response.headers.location, path),
379+
);
380+
return;
381+
}
382+
383+
// Save the file to disk
384+
const fileWriter: fs.WriteStream = fs
385+
.createWriteStream(path)
386+
.on('finish', (): void => {
387+
fileWriter.close();
388+
resolve({});
389+
});
390+
391+
response.pipe(fileWriter);
392+
});
393+
} else {
394+
const agent: https.Agent = new https.Agent({
395+
rejectUnauthorized: false,
396+
});
397+
https.get(url, {agent}, (response: http.IncomingMessage): void => {
371398
const code = response.statusCode ?? 0;
372399

373400
if (code >= 400) {
@@ -393,6 +420,7 @@ export default {
393420

394421
response.pipe(fileWriter);
395422
});
423+
}
396424
});
397425
},
398426

0 commit comments

Comments
 (0)