From 203958161106d234eaa85556293c1be8f8b395b3 Mon Sep 17 00:00:00 2001 From: Daniel Falbel Date: Fri, 5 Jul 2024 14:19:30 -0300 Subject: [PATCH] Use expand all command when testing the connections pane (#3855) This PR simplifies the connections pane smoke tests by using the `Expand all` command introduced in #3853. --------- Co-authored-by: Chris Mead --- .../src/positron/positronConnections.ts | 37 +++++++-------- test/automation/src/workbench.ts | 2 +- .../connections/dbConnections.test.ts | 45 +++++++++---------- 3 files changed, 40 insertions(+), 44 deletions(-) diff --git a/test/automation/src/positron/positronConnections.ts b/test/automation/src/positron/positronConnections.ts index 05bfda378b0..16b220c7ecc 100644 --- a/test/automation/src/positron/positronConnections.ts +++ b/test/automation/src/positron/positronConnections.ts @@ -5,16 +5,11 @@ import { Code } from '../code'; +import { QuickAccess } from '../quickaccess'; import { PositronBaseElement } from './positronBaseElement'; const REMOVE_CONNECTION_BUTTON = 'a[aria-label="Remove connection from history"]'; const DISCONNECT_BUTON = '.codicon-debug-disconnect'; -const PYTHON_SQLITE_CONNECTION = 'div[aria-label="SQLite Connection"]'; -const PYTHON_ROOT_NODE = 'div[aria-label="main"]'; - -const R_SQLITE_CONNECTION = 'a:has-text("SQLiteConnection")'; -const R_ROOT_NODE_1 = 'div[aria-label="SQLiteConnection"]:last-child'; -const R_ROOT_NODE_2 = 'div[aria-label="Default"]'; const PYTHON_CONNECTION_OPEN_STATE = 'div[aria-label="SQLite Connection"]'; const R_CONNECTION_OPEN_STATE = 'div[aria-label="SQLiteConnection"]:first-child'; @@ -34,7 +29,7 @@ export class PositronConnections { reconnectButton: PositronBaseElement; connectionsTabLink: PositronBaseElement; - constructor(private code: Code) { + constructor(private code: Code, private quickaccess: QuickAccess) { this.removeConnectionButton = new PositronBaseElement(REMOVE_CONNECTION_BUTTON, this.code); this.disconnectButton = new PositronBaseElement(DISCONNECT_BUTON, this.code); @@ -42,34 +37,36 @@ export class PositronConnections { this.pythonConnectionOpenState = new PositronBaseElement(PYTHON_CONNECTION_OPEN_STATE, this.code); this.reconnectButton = new PositronBaseElement(RECONNECT_BUTTON, this.code); this.connectionsTabLink = new PositronBaseElement(CONNECTIONS_TAB_LINK, this.code); - } async openConnectionsNodes(nodes: string[]) { - for (const node of nodes) { await this.code.waitAndClick(`div[aria-label="${node}"]`); } } + async hasConnectionNodes(nodes: string[]) { + const waits = nodes.map(async node => { + return await this.code.waitForElement(`div[aria-label="${node}"]`); + }); + await Promise.all(waits); + } + async hasConnectionNode(node: string) { const x = await this.code.getElement(`div[aria-label="${node}"]`); return x !== undefined; } - async openPythonTree() { - await this.code.waitAndClick(PYTHON_SQLITE_CONNECTION); - await this.code.waitAndClick(PYTHON_ROOT_NODE); + async openConnectionPane() { + await this.quickaccess.runCommand('connections.focus'); + await this.connectionPaneIsOpen(); // waiting for the pane to open } - async openRTree() { - - // not working due to timing: - // await app.code.waitAndClick('div[aria-label="SQLiteConnection"]'); - // workaround for above: - await this.code.driver.getLocator(R_SQLITE_CONNECTION).click(); + async connectionPaneIsOpen() { + await this.code.wait(500); + } - await this.code.waitAndClick(R_ROOT_NODE_1); - await this.code.waitAndClick(R_ROOT_NODE_2); + async openTree() { + await this.quickaccess.runCommand('positron.connections.expandAll'); } } diff --git a/test/automation/src/workbench.ts b/test/automation/src/workbench.ts index 6df04cbe97f..18522d5032f 100644 --- a/test/automation/src/workbench.ts +++ b/test/automation/src/workbench.ts @@ -109,7 +109,7 @@ export class Workbench { this.positronNotebooks = new PositronNotebooks(code, this.quickinput, this.quickaccess, this.notebook); this.positronNewProjectWizard = new PositronNewProjectWizard(code, this.quickaccess); this.positronExplorer = new PositronExplorer(code); - this.positronConnections = new PositronConnections(code); + this.positronConnections = new PositronConnections(code, this.quickaccess); this.positronHelp = new PositronHelp(code); // --- End Positron --- } diff --git a/test/smoke/src/areas/positron/connections/dbConnections.test.ts b/test/smoke/src/areas/positron/connections/dbConnections.test.ts index 4ec30686a0f..d4963d92f49 100644 --- a/test/smoke/src/areas/positron/connections/dbConnections.test.ts +++ b/test/smoke/src/areas/positron/connections/dbConnections.test.ts @@ -49,13 +49,11 @@ export function setup(logger: Logger) { logger.log('Opening connections pane'); await app.workbench.positronVariables.doubleClickVariableRow('conn'); - - await expect(async () => { - await app.workbench.positronConnections.openPythonTree(); - }).toPass(); + // in Python this will open all table connections, so should be fine. + await app.workbench.positronConnections.openTree(); // click in reverse order to avoid scrolling issues - await app.workbench.positronConnections.openConnectionsNodes(tables); + await app.workbench.positronConnections.hasConnectionNodes(['albums']); // disconnect icon appearance requires hover await app.workbench.positronConnections.pythonConnectionOpenState.hover(); @@ -96,16 +94,17 @@ export function setup(logger: Logger) { await app.workbench.quickaccess.openFile(join(app.workspacePathOrFolder, 'workspaces', 'chinook-db-r', 'sqlite.r')); await app.workbench.quickaccess.runCommand('r.sourceCurrentFile'); - logger.log('Opening connections pane'); - await app.workbench.positronConnections.connectionsTabLink.click(); - await expect(async () => { - await app.workbench.positronConnections.openRTree(); + logger.log('Opening connections pane'); + await app.workbench.positronConnections.openConnectionPane(); + await app.workbench.positronConnections.openTree(); + + // click in reverse order to avoid scrolling issues + // in R, the opneTree command only shows all tables, we click to also + // display fields + await app.workbench.positronConnections.openConnectionsNodes(tables); }).toPass(); - // click in reverse order to avoid scrolling issues - await app.workbench.positronConnections.openConnectionsNodes(tables); - // disconnect icon appearance requires hover await app.workbench.positronConnections.rConnectionOpenState.hover(); await app.workbench.positronConnections.disconnectButton.click(); @@ -127,24 +126,24 @@ export function setup(logger: Logger) { logger.log('Opening connections pane'); await app.workbench.positronConnections.connectionsTabLink.click(); - await expect(async () => { - await app.workbench.positronConnections.openRTree(); - }).toPass(); + await app.workbench.positronConnections.openTree(); const visible = await app.workbench.positronConnections.hasConnectionNode("mtcars"); if (visible) { throw new Error("mtcars should not be visible"); } + await expect(async () => { // now we add a dataframe to that connection - await app.workbench.positronConsole.executeCode( - 'R', - `DBI::dbWriteTable(con, "mtcars", mtcars)`, - '>' - ); - // the panel should be automatically updated and we should be able to see - // that table and click on it - await app.workbench.positronConnections.openConnectionsNodes(["mtcars"]); + await app.workbench.positronConsole.executeCode( + 'R', + `DBI::dbWriteTable(con, "mtcars", mtcars)`, + '>' + ); + // the panel should be automatically updated and we should be able to see + // that table and click on it + await app.workbench.positronConnections.openConnectionsNodes(["mtcars"]); + }).toPass(); });