Skip to content

Commit b9d8f94

Browse files
author
Guilherme Saraiva
committed
Refactor the execCmd function on E2e tests
Refactor the execCmd function on E2e tests Refactor the execCmd function on E2e tests Refactor the execCmd function on E2e tests - Use an interface to return the command results, like queries, shell commands, etc - This is composed by a new class, with several functions to deal with the multiple types of the command responses. - Implemented a new way to expect for new commands results Change-Id: I828223db2f3ed631f3a3a07c296dbb99a1cb7d3c
1 parent 1dcb220 commit b9d8f94

File tree

14 files changed

+1382
-895
lines changed

14 files changed

+1382
-895
lines changed

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

Lines changed: 808 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ export const openEditorsTreeSection = "OPEN EDITORS";
3939
export const tasksTreeSection = "MYSQL SHELL TASKS";
4040

4141
// TIMEOUTS
42+
export const wait150MiliSeconds = 150;
43+
export const wait2seconds = 2000;
4244
export const wait5seconds = 5000;
4345
export const wait10seconds = 10000;
4446
export const wait15seconds = 15000; //queryWaits
@@ -93,6 +95,8 @@ export const collapseAll = "Collapse All";
9395
export const mysqlRestService = "MySQL REST Service";
9496

9597
// CONTEXT MENUS ITEMS
98+
export const executeBlock = "Execute Block";
99+
export const executeBlockAndAdvance = "Execute Block and Advance";
96100
export const restartInternalShell = "Restart the Internal MySQL Shell Process";
97101
export const connectToExternalShell = "Connect to External MySQL Shell Process";
98102
export const relaunchWelcomeWizard = "Relaunch Welcome Wizard";

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

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ 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";
3839

3940
export class Database {
4041

@@ -217,8 +218,7 @@ export class Database {
217218
await Misc.switchBackToTopFrame();
218219
await Misc.clickSectionToolbarButton(await Misc.getSection(constants.dbTreeSection),
219220
constants.createDBConnection);
220-
await driver.wait(Until.tabIsOpened(constants.dbDefaultEditor), constants.wait5seconds,
221-
`${constants.dbDefaultEditor} tab was not opened`);
221+
await driver.wait(Until.tabIsOpened(constants.dbDefaultEditor), constants.wait5seconds);
222222
await Misc.switchToFrame();
223223
await driver.wait(until.elementLocated(locator.dbConnectionDialog.exists), constants.wait10seconds);
224224

@@ -273,6 +273,19 @@ export class Database {
273273
await dialog.findElement(locator.passwordDialog.ok).click();
274274
};
275275

276+
public static existsToolbarButton = async (button: string): Promise<boolean> => {
277+
const toolbar = await driver.wait(until.elementLocated(locator.notebook.toolbar.exists),
278+
constants.wait5seconds, "Toolbar was not found");
279+
const buttons = await toolbar.findElements(locator.notebook.toolbar.button.exists);
280+
for (const btn of buttons) {
281+
if ((await btn.getAttribute("data-tooltip")) === button) {
282+
return true;
283+
}
284+
}
285+
286+
return false;
287+
};
288+
276289
public static getToolbarButton = async (button: string): Promise<WebElement | undefined> => {
277290
const toolbar = await driver.wait(until.elementLocated(locator.notebook.toolbar.exists),
278291
constants.wait5seconds, "Toolbar was not found");
@@ -311,6 +324,32 @@ export class Database {
311324
}, constants.wait5seconds, "Could not set a new line on the editor");
312325
};
313326

327+
public static getMouseCursorLine = async (): Promise<number> => {
328+
const lines = await driver.findElements(locator.notebook.codeEditor.editor.lines);
329+
for (let i = 0; i <= lines.length - 1; i++) {
330+
const curLine = await lines[i].findElements(locator.notebook.codeEditor.editor.currentLine);
331+
if (curLine.length > 0) {
332+
return i;
333+
}
334+
}
335+
};
336+
337+
public static getLineFromWord = async (wordRef: string): Promise<number> => {
338+
const regex = wordRef
339+
.replace(/\*/g, "\\*")
340+
.replace(/\./g, ".*")
341+
.replace(/;/g, ".*")
342+
.replace(/\s/g, ".*");
343+
const lines = await driver.findElements(locator.notebook.codeEditor.editor.promptLine);
344+
for (let i = 0; i <= lines.length - 1; i++) {
345+
const lineContent = await lines[i].getAttribute("innerHTML");
346+
if (lineContent.match(regex)) {
347+
return i;
348+
}
349+
}
350+
throw new Error(`Could not find '${wordRef}'`);
351+
};
352+
314353
public static isStatementStart = async (statement: string): Promise<boolean | undefined> => {
315354

316355
const getLineSentence = async (ctx: WebElement): Promise<string> => {
@@ -1438,7 +1477,7 @@ export class Database {
14381477

14391478
const textArea = await driver?.findElement(locator.notebook.codeEditor.textArea);
14401479
await textArea.sendKeys(cmd);
1441-
await Misc.execOnEditor();
1480+
await CommandExecutor.exec();
14421481
timeout = timeout ?? 5000;
14431482

14441483
return Database.getScriptResult(timeout);

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
* 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2222
*/
2323

24+
import { WebElement } from "selenium-webdriver";
25+
2426
export interface IConnBasicMySQL {
2527
hostname?: string;
2628
protocol?: string;
@@ -206,3 +208,15 @@ export interface ITreeDBConnection {
206208
name: string;
207209
isMySQL: boolean;
208210
}
211+
212+
export interface ICommandResult {
213+
id: string;
214+
message: string;
215+
content: WebElement | ICommandTabResult[];
216+
toolbar: WebElement;
217+
}
218+
219+
export interface ICommandTabResult {
220+
tabName: string;
221+
content: string;
222+
}

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ export const notebook = {
8585
editor: {
8686
exists: By.className("monaco-editor-background"),
8787
host: By.id("editorPaneHost"),
88+
lines: By.css(".view-overlays > div"),
89+
promptLine: By.css(".view-lines.monaco-mouse-cursor-text > div"),
8890
sentence: By.css(".view-lines.monaco-mouse-cursor-text > div > span"),
8991
wordInSentence: By.css(".view-lines.monaco-mouse-cursor-text > div > span span"),
9092
line: By.css("#contentHost .editorHost .view-line"),
@@ -94,20 +96,17 @@ export const notebook = {
9496
autoCompleteListItem: By.css(".monaco-list .monaco-highlighted-label span"),
9597
result: {
9698
exists: By.className("zoneHost"),
97-
hasContent: By.className("renderTarget"),
99+
hasContent: By.className("content"),
98100
existsById: (view: string): By => {
99101
return By.xpath(`//div[@class='zoneHost' and @monaco-view-zone='${view}']`);
100102
},
101103
host: By.className("resultHost"),
102-
tabSection: {
103-
exists: By.className("resultTabview"),
104-
body: By.className("tabArea"),
105-
tab: By.css(".tabArea div"),
106-
tabname: By.css(".tabArea label"),
107-
},
108-
headers: By.className("tabulator-headers"),
104+
105+
table: By.className("tabulator"),
106+
tableRows: By.css(".tabulator-selectable.tabulator-row-odd"),
107+
tableHeaders: By.className("tabulator-headers"),
109108
tableColumnTitle: By.className("tabulator-col-title"),
110-
tableCell: By.css(".zoneHost .tabulator-cell"),
109+
tableCell: By.className("tabulator-cell"),
111110
status: {
112111
exists: By.className("resultStatus"),
113112
text: By.css(".resultStatus > label"),
@@ -116,15 +115,21 @@ export const notebook = {
116115
normalize: By.id("normalizeResultStateButton"),
117116
toolbar: By.css(".resultStatus .toolbar"),
118117
},
119-
text: By.className("resultText"),
118+
tabSection: {
119+
exists: By.className("tabAreaContainer"),
120+
body: By.className("tabArea"),
121+
tab: By.css(".tabArea .tabItem > label"),
122+
},
123+
text: By.css(".resultText > span"),
120124
graphHost: {
121125
exists: By.className("graphHost"),
122126
column: By.css("rect"),
123127
},
124128
json: {
125-
exists: By.className("jsonView"),
129+
exists: By.css(".actionOutput .jsonView"),
126130
field: By.css(".jsonView span > span"),
127131
},
132+
singleOutput: By.className("outputHost"),
128133
},
129134
},
130135
prompt: {
@@ -147,7 +152,7 @@ export const notebook = {
147152
};
148153

149154
export const shellSession = {
150-
exists: By.id("shellModuleHost"),
155+
exists: By.id("sessionSelector"),
151156
result: {
152157
label: By.className("actionLabel"),
153158
output: By.className("actionOutput"),
@@ -437,6 +442,10 @@ export const genericDialog = {
437442
exists: By.className("valueEditDialog"),
438443
};
439444

445+
export const suggestWidget = {
446+
exists: By.css(".suggest-widget.visible"),
447+
};
448+
440449
export const htmlTag = {
441450
img: By.css("img"),
442451
li: By.css("li"),

0 commit comments

Comments
 (0)