Skip to content

Commit 702ab56

Browse files
author
Guilherme Saraiva
committed
Fix CRUD tests and Windows rename log file
This patch fixes the CRUD tests and the renaming of log files for Windows - Does not fail if the renaming goes wrong Change-Id: Ib4f8bd342cd90f3cae9ef6e54bc71b168be0099f
1 parent 8d8d242 commit 702ab56

File tree

12 files changed

+183
-107
lines changed

12 files changed

+183
-107
lines changed

gui/extension/tests/e2e/lib/cmdExecutor.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import * as constants from "./constants";
3131
import * as locator from "./locators";
3232
import * as interfaces from "./interfaces";
3333
import { Misc, driver } from "./misc";
34-
import * as Until from "./until";
34+
import * as waitUntil from "./until";
3535

3636
/**
3737
* This class aggregates the functions that will execute commands on notebooks or shell sessions, as well as its results
@@ -297,8 +297,8 @@ export class CommandExecutor {
297297
if (await Database.existsToolbarButton(constants.execCaret)) {
298298
const toolbarButton = await Database.getToolbarButton(constants.execCaret);
299299
await toolbarButton.click();
300-
await driver.wait(Until.toolbarButtonIsDisabled(constants.execCaret), constants.wait5seconds);
301-
await driver.wait(Until.toolbarButtonIsEnabled(constants.execCaret), constants.wait5seconds);
300+
await driver.wait(waitUntil.toolbarButtonIsDisabled(constants.execCaret), constants.wait5seconds);
301+
await driver.wait(waitUntil.toolbarButtonIsEnabled(constants.execCaret), constants.wait5seconds);
302302
} else {
303303
await (await Database.getToolbarButton(constants.execFullBlockJs)).click();
304304
}
@@ -681,17 +681,17 @@ export class CommandExecutor {
681681
if (tableRows) {
682682
await driver.wait(until.stalenessOf(tableRows as WebElement), constants.wait2seconds,
683683
"Result table was not updated");
684-
await driver.wait(Until.elementLocated(result,
684+
await driver.wait(waitUntil.elementLocated(result,
685685
locator.notebook.codeEditor.editor.result.tableHeaders),
686686
constants.wait2seconds, "Result Table headers were not loaded");
687-
await driver.wait(Until.elementLocated(result,
687+
await driver.wait(waitUntil.elementLocated(result,
688688
locator.notebook.codeEditor.editor.result.tableCell),
689689
constants.wait2seconds, "Table cells were not loaded").catch(async () => {
690690
const result = fromScript ? await this
691691
.getResultScript() : await this.getResult(cmd, searchOnExistingId);
692692
await result.findElement(locator.notebook.codeEditor.editor.result.tableColumnTitle)
693693
.click();
694-
await driver.wait(Until
694+
await driver.wait(waitUntil
695695
.elementLocated(result, locator.notebook.codeEditor.editor.result.tableCell),
696696
constants.wait2seconds,
697697
`Table cell was not set after click on column title (bug)`);
@@ -710,16 +710,16 @@ export class CommandExecutor {
710710
}
711711
}
712712
} else if (isTableResult) {
713-
await driver.wait(Until.elementLocated(result,
713+
await driver.wait(waitUntil.elementLocated(result,
714714
locator.notebook.codeEditor.editor.result.tableHeaders),
715715
constants.wait2seconds, "Table headers were not loaded");
716-
await driver.wait(Until.elementLocated(result,
716+
await driver.wait(waitUntil.elementLocated(result,
717717
locator.notebook.codeEditor.editor.result.tableCell),
718718
constants.wait2seconds, "Table cells were not loaded").catch(async () => {
719719
const result = await this.getResult(cmd, searchOnExistingId);
720720
await result.findElement(locator.notebook.codeEditor.editor.result.tableColumnTitle)
721721
.click();
722-
await driver.wait(Until
722+
await driver.wait(waitUntil
723723
.elementLocated(result, locator.notebook.codeEditor.editor.result.tableCell),
724724
constants.wait2seconds, `Table cell was not set after click on column title (bug)`);
725725
});

gui/extension/tests/e2e/lib/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ export const bastionPassword = "MySQLR0cks!";
6060
// TIMEOUTS
6161
export const wait150MiliSeconds = 150;
6262
export const wait2seconds = 2000;
63+
export const wait3seconds = 3000;
6364
export const wait5seconds = 5000;
6465
export const wait10seconds = 10000;
6566
export const wait15seconds = 15000; //queryWaits

gui/extension/tests/e2e/lib/db.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import {
3030
} from "vscode-extension-tester";
3131
import { basename } from "path";
3232
import { driver, Misc } from "./misc";
33-
import * as Until from "./until";
33+
import * as waitUntil from "./until";
3434
import * as constants from "./constants";
3535
import * as interfaces from "./interfaces";
3636
import * as locator from "./locators";
@@ -217,7 +217,7 @@ export class Database {
217217
await Misc.switchBackToTopFrame();
218218
await Misc.clickSectionToolbarButton(await Misc.getSection(constants.dbTreeSection),
219219
constants.createDBConnection);
220-
await driver.wait(Until.tabIsOpened(constants.dbDefaultEditor), constants.wait5seconds);
220+
await driver.wait(waitUntil.tabIsOpened(constants.dbDefaultEditor), constants.wait5seconds);
221221
await Misc.switchToFrame();
222222
await driver.wait(until.elementLocated(locator.dbConnectionDialog.exists), constants.wait10seconds);
223223

@@ -1583,7 +1583,7 @@ export class Database {
15831583
public static setDBConnectionCredentials = async (data: interfaces.IDBConnection,
15841584
timeout?: number): Promise<void> => {
15851585
await Database.setPassword(data);
1586-
if (Until.credentialHelperOk) {
1586+
if (waitUntil.credentialHelperOk) {
15871587
await Misc.setConfirmDialog("no", timeout);
15881588
}
15891589
};

gui/extension/tests/e2e/lib/interfaces.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,5 +222,5 @@ export interface ICommandTabResult {
222222

223223
export interface ICommandResultIdHolder {
224224
id?: string;
225-
suite?: string
225+
suite?: string;
226226
}

gui/extension/tests/e2e/lib/misc.ts

Lines changed: 42 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,12 @@ import { join } from "path";
3030
import {
3131
BottomBarPanel, Condition, CustomTreeSection, EditorView, error, InputBox, ITimeouts,
3232
Key, OutputView, SideBarView, TreeItem, until, VSBrowser,
33-
WebDriver, ModalDialog,
33+
WebDriver, ModalDialog, NotificationType,
3434
WebElement, Workbench, Button, Notification,
3535
} from "vscode-extension-tester";
3636
import * as constants from "./constants";
3737
import { keyboard, Key as nutKey } from "@nut-tree/nut-js";
38-
import * as Until from "./until";
38+
import * as waitUntil from "./until";
3939
import * as locator from "./locators";
4040
import * as interfaces from "./interfaces";
4141
export let driver: WebDriver;
@@ -299,7 +299,7 @@ export class Misc {
299299
};
300300

301301
const treeDBSection = await Misc.getSection(constants.dbTreeSection);
302-
await driver.wait(Until.isNotLoading(constants.dbTreeSection), constants.wait5seconds);
302+
await driver.wait(waitUntil.isNotLoading(constants.dbTreeSection), constants.wait5seconds);
303303
await treeDBSection.click();
304304
const moreActions = await treeDBSection.findElement(locator.section.moreActions);
305305
await moreActions.click();
@@ -437,12 +437,17 @@ export class Misc {
437437

438438
public static prepareExtensionLogsForExport = async (testSuite: string): Promise<void> => {
439439
const logPathFolder = await Misc.getExtentionOutputLogsFolder();
440-
// rename the file
441-
await fs.rename(join(logPathFolder, constants.feLogFile),
442-
join(logPathFolder, `${testSuite}_output_tab.log`));
443-
// copy to workspace
444-
await fs.copyFile(join(logPathFolder, `${testSuite}_output_tab.log`),
445-
join(constants.workspace, `${testSuite}_output_tab.log`));
440+
try {
441+
// rename the file
442+
await fs.rename(join(logPathFolder, constants.feLogFile),
443+
join(logPathFolder, `${testSuite}_output_tab.log`));
444+
// copy to workspace
445+
await fs.copyFile(join(logPathFolder, `${testSuite}_output_tab.log`),
446+
join(constants.workspace, `${testSuite}_output_tab.log`));
447+
} catch (e) {
448+
// continue
449+
}
450+
446451
};
447452

448453
public static killRouterFromTerminal = (): void => {
@@ -607,13 +612,22 @@ export class Misc {
607612
}, constants.wait5seconds, "Could not switch back to top frame");
608613
};
609614

610-
public static getNotification = async (text: string, dismiss = true): Promise<Notification> => {
615+
public static getNotification = async (text: string, dismiss = true,
616+
expectFailure = false): Promise<Notification> => {
611617
let notif: Notification;
618+
619+
await driver.wait(waitUntil.notificationsExist(), constants.wait5seconds);
620+
612621
await driver.wait(async () => {
613622
try {
614623
const ntfs = await new Workbench().getNotifications();
615624
if (ntfs.length > 0) {
616625
for (const ntf of ntfs) {
626+
if (expectFailure === false) {
627+
if (await ntf.getType() === NotificationType.Error) {
628+
throw new Error("An error has occurred");
629+
}
630+
}
617631
if ((await ntf.getMessage()).includes(text)) {
618632
notif = ntf;
619633
if (dismiss) {
@@ -629,7 +643,7 @@ export class Misc {
629643
throw e;
630644
}
631645
}
632-
}, constants.wait10seconds, `Could not find '${text}' notification`);
646+
}, constants.wait2seconds, `Could not find '${text}' notification`);
633647

634648
return notif;
635649
};
@@ -705,6 +719,17 @@ export class Misc {
705719
}, timeout, `Could not find text '${textToSearch[0]}' on the terminal`);
706720
};
707721

722+
public static getRouterPort = async (): Promise<string> => {
723+
const routerConfigFilePath = Misc.getRouterConfigFile();
724+
const fileContent = (await fs.readFile(routerConfigFilePath)).toString();
725+
const lines = fileContent.split("\n");
726+
for (let i = 0; i <= lines.length - 1; i++) {
727+
if (lines[i] === "[http_server]") {
728+
return lines[i + 1].match(/port=(\d+)/)[1];
729+
}
730+
}
731+
};
732+
708733
public static terminalHasErrors = async (): Promise<boolean> => {
709734
const out = await Misc.getTerminalOutput();
710735

@@ -764,7 +789,7 @@ export class Misc {
764789
await inputBox.confirm();
765790
}
766791

767-
if (Until.credentialHelperOk) {
792+
if (waitUntil.credentialHelperOk) {
768793
await driver.wait(async () => {
769794
inputBox = await InputBox.create();
770795
if ((await inputBox.isPassword()) === false) {
@@ -1070,15 +1095,15 @@ export class Misc {
10701095
}
10711096

10721097
const sectionTree = await Misc.getSection(section);
1073-
await driver.wait(Until.isNotLoading(section), constants.wait20seconds);
1098+
await driver.wait(waitUntil.isNotLoading(section), constants.wait20seconds);
10741099
let reload = false;
10751100

10761101
await driver.wait(async () => {
10771102
try {
10781103
if (reload) {
10791104
if (section === constants.dbTreeSection || section === constants.ociTreeSection) {
10801105
await Misc.clickSectionToolbarButton(sectionTree, reloadLabel);
1081-
await driver.wait(Until.isNotLoading(section), constants.wait20seconds);
1106+
await driver.wait(waitUntil.isNotLoading(section), constants.wait20seconds);
10821107
}
10831108
}
10841109
if (itemName instanceof RegExp) {
@@ -1126,15 +1151,15 @@ export class Misc {
11261151
public static existsTreeElement = async (section: string, itemName: string | RegExp): Promise<boolean> => {
11271152
let reloadLabel: string;
11281153
const sectionTree = await Misc.getSection(section);
1129-
await driver.wait(Until.isNotLoading(section), constants.wait10seconds);
1154+
await driver.wait(waitUntil.isNotLoading(section), constants.wait10seconds);
11301155
if (section === constants.dbTreeSection || section === constants.ociTreeSection) {
11311156
if (section === constants.dbTreeSection) {
11321157
reloadLabel = "Reload the connection list";
11331158
} else if (section === constants.ociTreeSection) {
11341159
reloadLabel = "Reload the OCI Profile list";
11351160
}
11361161
await Misc.clickSectionToolbarButton(sectionTree, reloadLabel);
1137-
await driver.wait(Until.isNotLoading(section), constants.wait20seconds);
1162+
await driver.wait(waitUntil.isNotLoading(section), constants.wait20seconds);
11381163
}
11391164

11401165
if (itemName instanceof RegExp) {
@@ -1425,7 +1450,7 @@ export class Misc {
14251450
const treeItem = await Misc.getTreeElement(section, item);
14261451
if (!(await treeItem.isExpanded())) {
14271452
await treeItem.expand();
1428-
await driver.wait(Until.isNotLoading(section), loadingTimeout);
1453+
await driver.wait(waitUntil.isNotLoading(section), loadingTimeout);
14291454
}
14301455
}
14311456
};

gui/extension/tests/e2e/lib/until.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import {
2727
logging,
2828
WebElement,
2929
Locator,
30+
Workbench,
3031
} from "vscode-extension-tester";
3132
import { execSync } from "child_process";
3233
import { join } from "path";
@@ -38,6 +39,7 @@ import * as interfaces from "./interfaces";
3839
import { Database } from "./db";
3940
export let credentialHelperOk = true;
4041

42+
4143
export const isNotLoading = (section: string): Condition<boolean> => {
4244
return new Condition(`for ${section} to NOT be loading`, async () => {
4345
const sec = await Misc.getSection(section);
@@ -211,6 +213,33 @@ export const editorHasNewPrompt = (): Condition<boolean> => {
211213
});
212214
};
213215

216+
export const notificationsExist = (): Condition<boolean> => {
217+
return new Condition(`for notifications to be displayed`, async () => {
218+
return (await new Workbench().getNotifications()).length > 0;
219+
});
220+
};
221+
222+
export const fetchIsSuccessful = (url: string, data?: RequestInit): Condition<boolean> => {
223+
return new Condition(`for router ${url} to return success`, async () => {
224+
let response: Response;
225+
226+
return driver.wait(async () => {
227+
try {
228+
response = await fetch(url, data);
229+
230+
await response.json();
231+
232+
return true;
233+
} catch (e) {
234+
// continue
235+
console.log("-------");
236+
console.log(e);
237+
console.log("-------");
238+
}
239+
}, constants.wait5seconds, `Could not get URL for ${url}`);
240+
});
241+
};
242+
214243
export const routerIsRunning = (): Condition<boolean> => {
215244
return new Condition("for Router to be running", () => {
216245
if (Misc.isWindows()) {

0 commit comments

Comments
 (0)