Skip to content

Commit 5999324

Browse files
author
Guilherme Saraiva
committed
E2e extension tests refactor
- Refactor to be in accordance to the ICommandResult interface - Adds the executeScript function - Adds the getLastScriptResult function - Refactors other functions - Fixes a flaky test on FE - Adds new attributes to the CommandExecuter class Change-Id: I172a5f4e5eafd80c3aa798b1e7118617f76ad710
1 parent 7cb8421 commit 5999324

File tree

15 files changed

+816
-839
lines changed

15 files changed

+816
-839
lines changed

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

Lines changed: 360 additions & 305 deletions
Large diffs are not rendered by default.

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,24 @@ export const ociTreeSection = "ORACLE CLOUD INFRASTRUCTURE";
3838
export const openEditorsTreeSection = "OPEN EDITORS";
3939
export const tasksTreeSection = "MYSQL SHELL TASKS";
4040

41+
// OCI
42+
export const ociConfigProfile = {
43+
name: "E2ETESTS",
44+
user: "ocid1.user.oc1..aaaaaaaan67cojwa52khe44xtpqsygzxlk4te6gqs7nkmyabcju2w5wlxcpq",
45+
fingerprint: "15:cd:e2:11:ed:0b:97:c4:e4:41:c5:44:18:66:72:80",
46+
tenancy: "ocid1.tenancy.oc1..aaaaaaaaasur3qcs245czbgrlyshd7u5joblbvmxddigtubzqcfo5mmi2z3a",
47+
region: "us-ashburn-1",
48+
// eslint-disable-next-line @typescript-eslint/naming-convention
49+
key_file: `${process.env.MYSQLSH_OCI_CONFIG_FILE.replace("config", "")}id_rsa_e2e.pem`,
50+
};
51+
export const e2eTestsCompartment = "MySQLShellTesting";
52+
export const dbSystemType = "ociDbSystem";
53+
export const bastionType = "ociBastion";
54+
55+
// OCI E2E TESTS BASTION CREDENTIALS
56+
export const bastionUsername = "dba";
57+
export const bastionPassword = "MySQLR0cks!";
58+
4159
// TIMEOUTS
4260
export const wait150MiliSeconds = 150;
4361
export const wait2seconds = 2000;
@@ -354,3 +372,5 @@ export const openEditCtxMenu = new Map([
354372
export const miscCtxMenu = new Map([
355373
[openNotebookWithConn, 5],
356374
]);
375+
376+

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

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import * as constants from "./constants";
3535
import * as interfaces from "./interfaces";
3636
import * as locator from "./locators";
3737
import { keyboard, Key as nutKey } from "@nut-tree/nut-js";
38-
import { CommandExecutor } from "./cmdExecutor";
3938

4039
export class Database {
4140

@@ -1473,16 +1472,6 @@ export class Database {
14731472
return result;
14741473
};
14751474

1476-
public static execScript = async (cmd: string, timeout?: number): Promise<string> => {
1477-
1478-
const textArea = await driver?.findElement(locator.notebook.codeEditor.textArea);
1479-
await textArea.sendKeys(cmd);
1480-
await CommandExecutor.exec();
1481-
timeout = timeout ?? 5000;
1482-
1483-
return Database.getScriptResult(timeout);
1484-
};
1485-
14861475
public static getAutoCompleteMenuItems = async (): Promise<string[]> => {
14871476
const els = [];
14881477
let items = await driver.wait(until.elementsLocated(locator.notebook.codeEditor.editor.autoCompleteListItem),
@@ -1513,28 +1502,6 @@ export class Database {
15131502
return height > 0;
15141503
};
15151504

1516-
public static getScriptResult = async (timeout = constants.wait5seconds): Promise<string> => {
1517-
let toReturn = "";
1518-
await driver.wait(async () => {
1519-
const resultHost = await driver.findElements(locator.notebook.codeEditor.editor.result.host);
1520-
if (resultHost.length > 0) {
1521-
const status = await resultHost[resultHost.length - 1]
1522-
.findElements(locator.notebook.codeEditor.editor.result.status.text);
1523-
const output = await resultHost[resultHost.length - 1]
1524-
.findElements(locator.shellSession.result.outputText);
1525-
if (status.length > 0) {
1526-
toReturn = await status[status.length - 1].getAttribute("innerHTML");
1527-
} else if (output.length > 0) {
1528-
toReturn = await output[output.length - 1].getAttribute("innerHTML");
1529-
}
1530-
1531-
return true;
1532-
}
1533-
}, timeout, `No results were found`);
1534-
1535-
return toReturn;
1536-
};
1537-
15381505
public static clearInputField = async (el: WebElement): Promise<void> => {
15391506
await driver.wait(async () => {
15401507
await el.click();
@@ -1550,10 +1517,6 @@ export class Database {
15501517

15511518
};
15521519

1553-
public static isResultTabMaximized = async (): Promise<boolean> => {
1554-
return (await driver.findElements(locator.notebook.codeEditor.editor.result.status.normalize)).length > 0;
1555-
};
1556-
15571520
public static selectCurrentEditor = async (editorName: string, editorType: string): Promise<void> => {
15581521
const selector = await driver.findElement(locator.notebook.toolbar.editorSelector.exists);
15591522
await driver.executeScript("arguments[0].click()", selector);

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,17 @@ export interface ITreeDBConnection {
210210
}
211211

212212
export interface ICommandResult {
213-
id: string;
214-
message: string;
215-
content: WebElement | ICommandTabResult[];
216-
toolbar: WebElement;
213+
message?: string;
214+
content?: WebElement | ICommandTabResult[];
215+
toolbar?: WebElement;
217216
}
218217

219218
export interface ICommandTabResult {
220219
tabName: string;
221220
content: string;
222221
}
222+
223+
export interface ICommandResultIdHolder {
224+
id?: string;
225+
suite?: string
226+
}

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,22 @@ export const notebook = {
9494
currentLine: By.className("current-line"),
9595
statementStart: By.className("statementStart"),
9696
autoCompleteListItem: By.css(".monaco-list .monaco-highlighted-label span"),
97+
scrollBar: By.className("editor-scrollable"),
9798
result: {
9899
exists: By.className("zoneHost"),
99100
hasContent: By.className("content"),
100101
existsById: (view: string): By => {
101-
return By.xpath(`//div[@class='zoneHost' and @monaco-view-zone='${view}']`);
102+
let xpath = `//div[@class='zoneHost' and (`;
103+
xpath += `
104+
@monaco-view-zone='b${view}' or
105+
@monaco-view-zone='c${view}' or
106+
@monaco-view-zone='d${view}' or
107+
@monaco-view-zone='e${view}')]
108+
`;
109+
110+
return By.xpath(xpath);
102111
},
103112
host: By.className("resultHost"),
104-
105113
table: By.className("tabulator"),
106114
tableRows: By.css(".tabulator-selectable.tabulator-row-odd"),
107115
tableHeaders: By.className("tabulator-headers"),
@@ -130,6 +138,8 @@ export const notebook = {
130138
field: By.css(".jsonView span > span"),
131139
},
132140
singleOutput: By.className("outputHost"),
141+
script: By.className("standaloneScriptHost"),
142+
textOutput: By.css(".actionOutput span > span"),
133143
},
134144
},
135145
prompt: {

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

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* along with this program; if not, write to the Free Software Foundation, Inc.,
2121
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2222
*/
23+
2324
import { spawnSync, execSync } from "child_process";
2425
import clipboard from "clipboardy";
2526
import fs from "fs/promises";
@@ -32,7 +33,6 @@ import {
3233
WebDriver, ModalDialog,
3334
WebElement, Workbench, Button, Notification,
3435
} from "vscode-extension-tester";
35-
import { Database } from "./db";
3636
import * as constants from "./constants";
3737
import { keyboard, Key as nutKey } from "@nut-tree/nut-js";
3838
import * as Until from "./until";
@@ -745,30 +745,6 @@ export class Misc {
745745
}
746746
};
747747

748-
public static cleanEditor = async (): Promise<void> => {
749-
await driver.wait(async () => {
750-
try {
751-
const textArea = await driver.findElement(locator.notebook.codeEditor.textArea);
752-
if (Misc.isMacOs()) {
753-
await textArea.sendKeys(Key.chord(Key.COMMAND, "a", "a"));
754-
} else {
755-
await textArea.sendKeys(Key.chord(Key.CONTROL, "a", "a"));
756-
}
757-
758-
await textArea.sendKeys(Key.BACK_SPACE);
759-
await driver.wait(async () => {
760-
return await Database.getPromptLastTextLine() === "";
761-
}, 3000, "Prompt was not cleaned");
762-
763-
return true;
764-
} catch (e) {
765-
if (!(e instanceof error.StaleElementReferenceError)) {
766-
throw e;
767-
}
768-
}
769-
}, constants.wait5seconds, "Editor was not cleaned");
770-
};
771-
772748
public static getResultTabs = async (resultHost: WebElement): Promise<string[]> => {
773749

774750
const result: string[] = [];
@@ -1059,6 +1035,21 @@ export class Misc {
10591035
return el;
10601036
};
10611037

1038+
public static getTreeElementByType = async (section: string, type: string): Promise<TreeItem> => {
1039+
1040+
const sectionTree = await Misc.getSection(section);
1041+
const treeItems = await sectionTree.getVisibleItems();
1042+
for (const treeItem of treeItems) {
1043+
const el = await treeItem.findElement(locator.section.itemIcon);
1044+
const backImage = await el.getCssValue("background-image");
1045+
if (backImage.match(new RegExp(type)) !== null) {
1046+
return treeItem;
1047+
}
1048+
}
1049+
1050+
throw new Error(`Could not find the item type ${type} on section ${section}`);
1051+
};
1052+
10621053
public static existsTreeElement = async (section: string, itemName: string | RegExp): Promise<boolean> => {
10631054
let reloadLabel: string;
10641055
const sectionTree = await Misc.getSection(section);

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

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
* along with this program; if not, write to the Free Software Foundation, Inc.,
2121
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2222
*/
23-
import { until, Condition } from "vscode-extension-tester";
23+
24+
import { Condition } from "vscode-extension-tester";
2425
import { driver } from "./misc";
2526
import * as locator from "./locators";
2627

@@ -36,21 +37,4 @@ export class Shell {
3637
});
3738
};
3839

39-
public static changeSchemaOnTab = async (schema: string): Promise<void> => {
40-
const tabSchema = await driver.findElement(locator.shellConsole.connectionTab.schema);
41-
await tabSchema.click();
42-
const menu = await driver.wait(until.elementLocated(locator.shellConsole.connectionTab.schemaMenu),
43-
3000, "Schema list was not displayed");
44-
const items = await menu.findElements(locator.shellConsole.connectionTab.schemaItem);
45-
for (const item of items) {
46-
if ((await item.getAttribute("innerHTML")).includes(schema)) {
47-
await item.click();
48-
break;
49-
}
50-
}
51-
52-
await driver.wait(async () => {
53-
return (await driver.findElement(locator.shellConsole.connectionTab.schema).getText()).includes(schema);
54-
}, 3000, `${schema} was not selected`);
55-
};
5640
}

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,27 @@ export const toolbarButtonIsEnabled = (button: string): Condition<boolean> => {
190190
});
191191
};
192192

193+
export const resultTabIsMaximized = (): Condition<boolean> => {
194+
return new Condition(`for result tab to be maximezed`, async () => {
195+
return (await driver.findElements(locator.notebook.codeEditor.editor.result.status.normalize)).length > 0;
196+
});
197+
};
198+
199+
export const resultTabIsNormalized = (): Condition<boolean> => {
200+
return new Condition(`for result tab to be maximezed`, async () => {
201+
return (await driver.findElements(locator.notebook.codeEditor.editor.result.status.normalize)).length === 0;
202+
});
203+
};
204+
205+
export const editorHasNewPrompt = (): Condition<boolean> => {
206+
return new Condition(`for editor to have a new prompt`, async () => {
207+
const editorSentences = await driver.findElements(locator.notebook.codeEditor.editor.sentence);
208+
209+
return (await (editorSentences[editorSentences.length - 1]).getAttribute("innerHTML"))
210+
.match(/<span><\/span>/) !== null;
211+
});
212+
};
213+
193214
export const routerIsRunning = (): Condition<boolean> => {
194215
return new Condition("for Router to be running", () => {
195216
if (Misc.isWindows()) {

gui/extension/tests/e2e/powershell/setup.ps1

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -300,10 +300,11 @@ try {
300300
writeMsg "DONE"
301301
} else {
302302
if ($isLinux) {
303-
$link = Join-Path $config "plugin_data" "gui_plugin" "web_certs"
304-
writeMsg "Re-creating the symbolic link for $link ..." "-NoNewLine"
305-
Remove-Item -Path $link -Force
306-
New-Item -ItemType SymbolicLink -Path $link -Target $targetWebCerts
303+
$webCerts = Join-Path $config "plugin_data" "gui_plugin" "web_certs"
304+
$destination = Join-Path $config "plugin_data" "gui_plugin"
305+
writeMsg "Copying web certs to $destination ..." "-NoNewLine"
306+
Remove-Item -Path $webCerts -Force -Recurse
307+
Copy-Item -Path $targetWebCerts -Destination $destination -Force -Recurse
307308
writeMsg "DONE"
308309
}
309310
}

0 commit comments

Comments
 (0)