Skip to content

Commit bdebdc5

Browse files
author
Guilherme Saraiva
committed
Locators E2e FE tests
Last patch to refactor locators for FE tests Change-Id: I21cb98a316d4c7d7cb4e9a5cd4940eca3766ef0d
1 parent 49f4788 commit bdebdc5

File tree

11 files changed

+255
-531
lines changed

11 files changed

+255
-531
lines changed

gui/extension/tests/e2e/tests/ui-shell.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,7 @@ describe("MYSQL SHELL CONSOLES", () => {
164164

165165
it("Connect to host", async () => {
166166
let connUri = `\\c ${username}:${password}@${hostname}:${port}/${schema}`;
167+
await driver.wait(waitUntil.shellSessionIsOpened(shellConn), constants.wait15seconds);
167168
await commandExecutor.execute(connUri);
168169
connUri = `Creating a session to '${username}@${hostname}:${port}/${schema}'`;
169170
expect(commandExecutor.getResultMessage(), errors.queryResultError(connUri,

gui/frontend/src/tests/e2e/lib/dbNotebooks.ts

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

24-
import { By, until, WebElement, Key, error, WebDriver } from "selenium-webdriver";
24+
import { until, WebElement, Key, error, WebDriver } from "selenium-webdriver";
2525
import { explicitWait, IDBConnection } from "./misc.js";
26+
import * as locator from "../lib/locators.js";
2627

2728
export const execFullBlockSql = "Execute the selection or everything in the current block and create a new block";
2829
export const execFullBlockJs = "Execute everything in the current block and create a new block";
@@ -43,11 +44,11 @@ export class DBNotebooks {
4344
* @returns Promise resolving when the select is made
4445
*/
4546
public static selectDBType = async (driver: WebDriver, value: string): Promise<void> => {
46-
await driver.findElement(By.id("databaseType")).click();
47-
const dropDownList = await driver.findElement(By.css(".dropdownList"));
48-
const els = await dropDownList.findElements(By.css("div"));
47+
await driver.findElement(locator.databaseConnectionConfiguration.databaseType.exists).click();
48+
const dropDownList = await driver.findElement(locator.databaseConnectionConfiguration.databaseType.list);
49+
const els = await dropDownList.findElements(locator.htmlTag.div);
4950
if (els.length > 0) {
50-
await dropDownList.findElement(By.id(value)).click();
51+
await dropDownList.findElement(locator.searchById(value)).click();
5152
}
5253
};
5354

@@ -58,9 +59,9 @@ export class DBNotebooks {
5859
* @returns Promise resolving when the select is made
5960
*/
6061
public static setProtocol = async (driver: WebDriver, value: string): Promise<void> => {
61-
await driver.findElement(By.id("scheme")).click();
62-
const dropDownList = await driver.findElement(By.css(".dropdownList"));
63-
await dropDownList.findElement(By.id(value)).click();
62+
await driver.findElement(locator.databaseConnectionConfiguration.mysql.basic.protocol.exists).click();
63+
const dropDownList = await driver.findElement(locator.databaseConnectionConfiguration.mysql.basic.protocol.list);
64+
await dropDownList.findElement(locator.searchById(value)).click();
6465
};
6566

6667
/**
@@ -70,9 +71,9 @@ export class DBNotebooks {
7071
* @returns Promise resolving when the select is made
7172
*/
7273
public static setSSLMode = async (driver: WebDriver, value: string): Promise<void> => {
73-
await driver.findElement(By.id("sslMode")).click();
74-
const dropDownList = await driver.findElement(By.css(".dropdownList"));
75-
await dropDownList.findElement(By.id(value)).click();
74+
await driver.findElement(locator.databaseConnectionConfiguration.mysql.ssl.mode).click();
75+
const dropDownList = await driver.findElement(locator.databaseConnectionConfiguration.mysql.ssl.modeList.exists);
76+
await dropDownList.findElement(locator.searchById(value)).click();
7677
};
7778

7879
/**
@@ -83,16 +84,16 @@ export class DBNotebooks {
8384
* @returns Promise resolving with the connection created
8485
*/
8586
public static createDBconnection = async (driver: WebDriver, dbConfig: IDBConnection): Promise<WebElement | undefined> => {
86-
const ctx = await driver.wait(until.elementLocated(By.css(".connectionBrowser")),
87+
const ctx = await driver.wait(until.elementLocated(locator.dbConnections.browser),
8788
explicitWait, "DB Connection Overview page was not loaded");
8889

8990
await driver.wait(async () => {
90-
const isDialogVisible = (await driver.findElements(By.css(".valueEditDialog"))).length > 0;
91+
const isDialogVisible = (await driver.findElements(locator.databaseConnectionConfiguration.exists)).length > 0;
9192
if (isDialogVisible) {
9293
return true;
9394
} else {
9495
try {
95-
await ctx.findElement(By.id("-1")).click();
96+
await ctx.findElement(locator.dbConnections.newConnection).click();
9697
} catch (e) {
9798
if (!(e instanceof error.ElementClickInterceptedError)) {
9899
throw e;
@@ -103,56 +104,56 @@ export class DBNotebooks {
103104
}
104105
}, explicitWait, "Connection dialog was not displayed");
105106

106-
const newConDialog = await driver.findElement(By.css(".valueEditDialog"));
107+
const newConDialog = await driver.findElement(locator.databaseConnectionConfiguration.exists);
107108

108109
await driver.wait(async () => {
109-
await newConDialog.findElement(By.id("caption")).clear();
110+
await newConDialog.findElement(locator.databaseConnectionConfiguration.caption).clear();
110111

111112
return !(await driver.executeScript("return document.querySelector('#caption').value"));
112113
}, 3000, "caption was not cleared in time");
113-
await newConDialog.findElement(By.id("caption")).sendKeys(dbConfig.caption);
114-
await newConDialog.findElement(By.id("description")).clear();
114+
await newConDialog.findElement(locator.databaseConnectionConfiguration.caption).sendKeys(dbConfig.caption);
115+
await newConDialog.findElement(locator.databaseConnectionConfiguration.description).clear();
115116
await newConDialog
116-
.findElement(By.id("description"))
117+
.findElement(locator.databaseConnectionConfiguration.description)
117118
.sendKeys(dbConfig.description);
118-
await newConDialog.findElement(By.id("hostName")).clear();
119-
await newConDialog.findElement(By.id("hostName")).sendKeys(String(dbConfig.hostname));
119+
await newConDialog.findElement(locator.databaseConnectionConfiguration.mysql.basic.hostname).clear();
120+
await newConDialog.findElement(locator.databaseConnectionConfiguration.mysql.basic.hostname).sendKeys(String(dbConfig.hostname));
120121
await DBNotebooks.setProtocol(driver, dbConfig.protocol);
121-
await driver.findElement(By.css("#port input")).clear();
122-
await driver.findElement(By.css("#port input")).sendKeys(String(dbConfig.port));
123-
await newConDialog.findElement(By.id("userName")).sendKeys(String(dbConfig.username));
122+
await driver.findElement(locator.databaseConnectionConfiguration.mysql.basic.port).clear();
123+
await driver.findElement(locator.databaseConnectionConfiguration.mysql.basic.port).sendKeys(String(dbConfig.port));
124+
await newConDialog.findElement(locator.databaseConnectionConfiguration.mysql.basic.username).sendKeys(String(dbConfig.username));
124125
await newConDialog
125-
.findElement(By.id("defaultSchema"))
126+
.findElement(locator.databaseConnectionConfiguration.mysql.basic.schema)
126127
.sendKeys(String(dbConfig.schema));
127128

128129
if (dbConfig.dbType) {
129130
await DBNotebooks.selectDBType(driver, dbConfig.dbType);
130131
}
131132

132133
if (dbConfig.sslMode) {
133-
await newConDialog.findElement(By.id("page1")).click();
134-
await newConDialog.findElement(By.id("sslMode")).click();
135-
const dropDownList = await driver.findElement(By.css(".noArrow.dropdownList"));
136-
await dropDownList.findElement(By.id(dbConfig.sslMode)).click();
137-
expect(await newConDialog.findElement(By.css("#sslMode label")).getText())
134+
await newConDialog.findElement(locator.databaseConnectionConfiguration.sslTab).click();
135+
await newConDialog.findElement(locator.databaseConnectionConfiguration.mysql.ssl.mode).click();
136+
const dropDownList = await driver.findElement(locator.databaseConnectionConfiguration.mysql.ssl.modeList.exists);
137+
await dropDownList.findElement(locator.searchById(dbConfig.sslMode)).click();
138+
expect(await newConDialog.findElement(locator.databaseConnectionConfiguration.mysql.ssl.modeLabel).getText())
138139
.toBe(dbConfig.sslMode);
139140

140141
const certsPath = process.env.SSLCERTSPATH as string;
141-
const paths = await newConDialog.findElements(By.css(".tabview.top input.msg"));
142+
const paths = await newConDialog.findElements(locator.databaseConnectionConfiguration.mysql.ssl.inputs);
142143
await paths[0].sendKeys(`${certsPath}/ca-cert.pem`);
143144
await paths[1].sendKeys(`${certsPath}/client-cert.pem`);
144145
await paths[2].sendKeys(`${certsPath}/client-key.pem`);
145146
}
146147

147-
const okBtn = await driver.findElement(By.id("ok"));
148+
const okBtn = await driver.findElement(locator.databaseConnectionConfiguration.ok);
148149
await driver.executeScript("arguments[0].scrollIntoView(true)", okBtn);
149150
await okBtn.click();
150-
expect((await driver.findElements(By.css(".valueEditDialog"))).length).toBe(0);
151+
expect((await driver.findElements(locator.databaseConnectionConfiguration.exists)).length).toBe(0);
151152

152153
return driver.wait(async () => {
153-
const connections = await driver.findElements(By.css("#tilesHost .connectionTile"));
154+
const connections = await driver.findElements(locator.dbConnections.connections.item);
154155
for (const connection of connections) {
155-
const el = await connection.findElement(By.css(".textHost .tileCaption"));
156+
const el = await connection.findElement(locator.dbConnections.connections.caption);
156157
if ((await el.getAttribute("innerHTML")).includes(dbConfig.caption)) {
157158
return connection;
158159
}
@@ -170,9 +171,9 @@ export class DBNotebooks {
170171
public static getConnection = async (driver: WebDriver, name: string): Promise<WebElement | undefined> => {
171172

172173
return driver.wait(async () => {
173-
const connections = await driver.findElements(By.css("#tilesHost .connectionTile"));
174+
const connections = await driver.findElements(locator.dbConnections.connections.item);
174175
for (const connection of connections) {
175-
const el = await connection.findElement(By.css(".textHost .tileCaption"));
176+
const el = await connection.findElement(locator.dbConnections.connections.caption);
176177
if ((await el.getAttribute("innerHTML")).includes(name)) {
177178
return connection;
178179
}
@@ -182,35 +183,36 @@ export class DBNotebooks {
182183
};
183184

184185
public static clickConnectionItem = async (driver: WebDriver, conn: WebElement, item: string): Promise<void> => {
185-
const moreActions = await conn.findElement(By.id("tileMoreActionsAction"));
186+
const moreActions = await conn.findElement(locator.dbConnections.connections.actions.moreActions);
186187
const moreActionsRect = await moreActions.getRect();
187188
await driver.actions().move({
188189
x: parseInt(`${moreActionsRect.x}`, 10),
189190
y: parseInt(`${moreActionsRect.y}`, 10),
190191
}).perform();
191192
switch (item) {
192193
case "notebook": {
193-
await conn.findElement(By.id("tileNewNotebookAction")).click();
194+
await conn.findElement(locator.dbConnections.connections.actions.newNotebook).click();
194195
break;
195196
}
196197
case "script": {
197-
await conn.findElement(By.id("tileNewScriptAction")).click();
198+
await conn.findElement(locator.dbConnections.connections.actions.newScript).click();
198199
break;
199200
}
200201
case "edit": {
201202
await moreActions.click();
202-
await driver.wait(until.elementLocated(By.id("edit")), explicitWait, "Edit button not found").click();
203+
await driver.wait(until.elementLocated(locator.dbConnections.connections.actions.edit),
204+
explicitWait, "Edit button not found").click();
203205
break;
204206
}
205207
case "duplicate": {
206208
await moreActions.click();
207-
await driver.wait(until.elementLocated(By.id("duplicate")),
209+
await driver.wait(until.elementLocated(locator.dbConnections.connections.actions.duplicate),
208210
explicitWait, "Duplicate button not found").click();
209211
break;
210212
}
211213
case "remove": {
212214
await moreActions.click();
213-
await driver.wait(until.elementLocated(By.id("remove")),
215+
await driver.wait(until.elementLocated(locator.dbConnections.connections.actions.remove),
214216
explicitWait, "Remove button not found").click();
215217
break;
216218
}
@@ -227,7 +229,7 @@ export class DBNotebooks {
227229
*/
228230
public static getAutoCompleteMenuItems = async (driver: WebDriver,): Promise<string[]> => {
229231
const els = [];
230-
let items = await driver.wait(until.elementsLocated(By.css(".monaco-list .monaco-highlighted-label")),
232+
let items = await driver.wait(until.elementsLocated(locator.notebook.codeEditor.autoCompleteItems),
231233
explicitWait, "Auto complete items were not displayed");
232234

233235
for (const item of items) {
@@ -236,15 +238,14 @@ export class DBNotebooks {
236238

237239
await driver.actions().sendKeys(Key.ARROW_UP).perform();
238240

239-
items = await driver.wait(until.elementsLocated(By.css(".monaco-list .monaco-highlighted-label")),
241+
items = await driver.wait(until.elementsLocated(locator.notebook.codeEditor.autoCompleteItems),
240242
explicitWait, "Auto complete items were not displayed");
241243

242244
for (const item of items) {
243245
els.push(await item.getText());
244246
}
245247

246248
return [...new Set(els)];
247-
248249
};
249250

250251
/**
@@ -253,9 +254,9 @@ export class DBNotebooks {
253254
* @returns A promise resolving with the line number
254255
*/
255256
public static getMouseCursorLine = async (driver: WebDriver): Promise<number | undefined> => {
256-
const lines = await driver.findElements(By.css(".view-overlays > div"));
257+
const lines = await driver.findElements(locator.notebook.codeEditor.editor.cursorLine);
257258
for (let i = 0; i <= lines.length - 1; i++) {
258-
const curLine = await lines[i].findElements(By.className("current-line"));
259+
const curLine = await lines[i].findElements(locator.notebook.codeEditor.editor.currentLine);
259260
if (curLine.length > 0) {
260261
return i;
261262
}
@@ -277,7 +278,7 @@ export class DBNotebooks {
277278
let line;
278279
await driver.wait(async () => {
279280
try {
280-
const lines = await driver.findElements(By.css(".view-lines.monaco-mouse-cursor-text > div"));
281+
const lines = await driver.findElements(locator.notebook.codeEditor.editor.editorPrompt);
281282
for (let i = 0; i <= lines.length - 1; i++) {
282283
const lineContent = await lines[i].getAttribute("innerHTML");
283284
if (lineContent.match(regex)) {
@@ -308,11 +309,9 @@ export class DBNotebooks {
308309
*/
309310
public static setMouseCursorAt = async (driver: WebDriver, word: string): Promise<void> => {
310311
const mouseCursorIs = await DBNotebooks.getMouseCursorLine(driver);
311-
console.log(`mouseCursorIs: ${mouseCursorIs}`);
312312
const mouseCursorShouldBe = await DBNotebooks.getLineFromWord(driver, word);
313-
console.log(`mouseCursorShouldBe: ${mouseCursorShouldBe}`);
314313
const taps = mouseCursorShouldBe - mouseCursorIs!;
315-
const textArea = await driver.findElement(By.css("textarea"));
314+
const textArea = await driver.findElement(locator.notebook.codeEditor.textArea);
316315
if (taps > 0) {
317316
for (let i = 0; i < taps; i++) {
318317
await textArea.sendKeys(Key.ARROW_DOWN);

gui/frontend/src/tests/e2e/lib/guiConsole.ts

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

24-
import { By, until, WebElement, WebDriver } from "selenium-webdriver";
24+
import { until, WebElement, WebDriver, error } from "selenium-webdriver";
25+
import * as locator from "../lib/locators.js";
2526

2627
export class GuiConsole {
2728

@@ -35,19 +36,19 @@ export class GuiConsole {
3536
*/
3637
public static openSession = async (driver: WebDriver, id?: number): Promise<void> => {
3738
if (id) {
38-
const buttons = await driver.findElements(By.css("#shellModuleHost #tilesHost button"));
39+
const buttons = await driver.findElements(locator.shellPage.sessions.open);
3940
for (const button of buttons) {
4041
if ((await button.getAttribute("id")) === String(id)) {
4142
await button.click();
4243
break;
4344
}
4445
}
4546
} else {
46-
await driver.findElement(By.css("#shellModuleHost #\\-1")).click();
47+
await driver.findElement(locator.shellPage.sessions.newSession).click();
4748
}
4849

4950
await driver.wait(
50-
until.elementLocated(By.id("shellEditorHost")),
51+
until.elementLocated(locator.shellSession.exists),
5152
15000,
5253
"Session was not opened",
5354
);
@@ -61,16 +62,14 @@ export class GuiConsole {
6162
*/
6263
public static getSession = async (driver: WebDriver, sessionNbr: string): Promise<WebElement | undefined> => {
6364
try {
64-
const buttons = await driver.findElements(By.css("#shellModuleHost #tilesHost .sessionTile"));
65+
const buttons = await driver.findElements(locator.shellPage.sessions.tile);
6566
for (const button of buttons) {
6667
if ((await button.getAttribute("id")) === sessionNbr) {
6768
return button;
6869
}
6970
}
7071
} catch (e) {
71-
if (typeof e === "object" && String(e).includes("StaleElementReferenceError")) {
72-
return undefined;
73-
} else {
72+
if (!(e instanceof error.StaleElementReferenceError)) {
7473
throw e;
7574
}
7675
}

0 commit comments

Comments
 (0)