Skip to content

Commit cae259e

Browse files
committed
refactoring
1 parent 9895197 commit cae259e

File tree

5 files changed

+89
-41
lines changed

5 files changed

+89
-41
lines changed

Diff for: test/automation/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -39,5 +39,6 @@ export * from './positron/fixtures/positronRFixtures';
3939
export * from './positron/positronBaseElement';
4040
export * from './positron/positronNotebooks';
4141
export * from './positron/positronNewProjectWizard';
42+
export * from './positron/positronConnections';
4243
// --- End Positron ---
4344
export { getDevElectronPath, getBuildElectronPath, getBuildVersion } from './electron';

Diff for: test/automation/src/positron/positronBaseElement.ts

+4
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ export class PositronBaseElement {
2626
async waitforVisible(): Promise<void> {
2727
await this.code.waitForElement(this.myselector);
2828
}
29+
30+
async hover(): Promise<void> {
31+
await this.code.driver.getLocator(this.myselector).hover();
32+
}
2933
}
3034

3135
export class PositronTextElement extends PositronBaseElement {

Diff for: test/automation/src/positron/positronConnections.ts

+66
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (C) 2024 Posit Software, PBC. All rights reserved.
3+
*--------------------------------------------------------------------------------------------*/
4+
5+
6+
import { Code } from '../code';
7+
import { PositronBaseElement } from './positronBaseElement';
8+
9+
const REMOVE_CONNECTION_BUTTON = 'a[aria-label="Remove connection from history"]';
10+
const DISCONNECT_BUTON = '.codicon-debug-disconnect';
11+
const PYTHON_SQLITE_CONNECTION = 'div[aria-label="SQLite Connection"]';
12+
const PYTHON_ROOT_NODE = 'div[aria-label="main"]';
13+
14+
const R_SQLITE_CONNECTION = 'a:has-text("SQLiteConnection")';
15+
const R_ROOT_NODE_1 = 'div[aria-label="SQLiteConnection"]:last-child';
16+
const R_ROOT_NODE_2 = 'div[aria-label="Default"]';
17+
18+
const PYTHON_CONNECTION_OPEN_STATE = 'div[aria-label="SQLite Connection"]';
19+
const R_CONNECTION_OPEN_STATE = 'div[aria-label="SQLiteConnection"]:first-child';
20+
const RECONNECT_BUTTON = 'a[aria-label="Execute connection code in the console"]';
21+
22+
const CONNECTIONS_TAB_LINK = 'a[aria-label="Connections"]';
23+
24+
export class PositronConnections {
25+
26+
removeConnectionButton: PositronBaseElement;
27+
disonnectButton: PositronBaseElement;
28+
rConnectionOpenState: PositronBaseElement;
29+
pythonConnectionOpenState: PositronBaseElement;
30+
reconnectButton: PositronBaseElement;
31+
connectionsTabLink: PositronBaseElement;
32+
33+
constructor(private code: Code) {
34+
35+
this.removeConnectionButton = new PositronBaseElement(REMOVE_CONNECTION_BUTTON, this.code);
36+
this.disonnectButton = new PositronBaseElement(DISCONNECT_BUTON, this.code);
37+
this.rConnectionOpenState = new PositronBaseElement(R_CONNECTION_OPEN_STATE, this.code);
38+
this.pythonConnectionOpenState = new PositronBaseElement(PYTHON_CONNECTION_OPEN_STATE, this.code);
39+
this.reconnectButton = new PositronBaseElement(RECONNECT_BUTTON, this.code);
40+
this.connectionsTabLink = new PositronBaseElement(CONNECTIONS_TAB_LINK, this.code);
41+
42+
}
43+
44+
async openConnectionsNodes(nodes: string[]) {
45+
46+
for (const node of nodes) {
47+
await this.code.waitAndClick(`div[aria-label="${node}"]`);
48+
}
49+
}
50+
51+
async openPythonTable() {
52+
await this.code.waitAndClick(PYTHON_SQLITE_CONNECTION);
53+
await this.code.waitAndClick(PYTHON_ROOT_NODE);
54+
}
55+
56+
async openRTable() {
57+
58+
// not working due to timing:
59+
// await app.code.waitAndClick('div[aria-label="SQLiteConnection"]');
60+
// workaround for above:
61+
await this.code.driver.getLocator(R_SQLITE_CONNECTION).click();
62+
63+
await this.code.waitAndClick(R_ROOT_NODE_1);
64+
await this.code.waitAndClick(R_ROOT_NODE_2);
65+
}
66+
}

Diff for: test/automation/src/workbench.ts

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import { PositronPlots } from './positron/positronPlots';
3434
import { PositronNotebooks } from './positron/positronNotebooks';
3535
import { PositronNewProjectWizard } from './positron/positronNewProjectWizard';
3636
import { PositronExplorer } from './positron/positronExplorer';
37+
import { PositronConnections } from './positron/positronConnections';
3738
// --- End Positron ---
3839

3940
export interface Commands {
@@ -72,6 +73,7 @@ export class Workbench {
7273
readonly positronNotebooks: PositronNotebooks;
7374
readonly positronNewProjectWizard: PositronNewProjectWizard;
7475
readonly positronExplorer: PositronExplorer;
76+
readonly positronConnections: PositronConnections;
7577
// --- End Positron ---
7678

7779
constructor(code: Code) {
@@ -105,6 +107,7 @@ export class Workbench {
105107
this.positronNotebooks = new PositronNotebooks(code, this.quickinput, this.quickaccess, this.notebook);
106108
this.positronNewProjectWizard = new PositronNewProjectWizard(code, this.quickaccess);
107109
this.positronExplorer = new PositronExplorer(code);
110+
this.positronConnections = new PositronConnections(code);
108111
// --- End Positron ---
109112
}
110113
}

Diff for: test/smoke/src/areas/positron/connections/dbConnections.test.ts

+15-41
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ export function setup(logger: Logger) {
1111

1212
describe('Connections Pane', () => {
1313

14+
const tables = ['tracks', 'playlist_track', 'playlists', 'media_types', 'invoice_items', 'invoices', 'genres', 'employees', 'customers', 'artists', 'albums'];
15+
1416
// Shared before/after handling
1517
installAllHandlers(logger);
1618

@@ -28,7 +30,7 @@ export function setup(logger: Logger) {
2830
after(async function () {
2931

3032
const app = this.app as Application;
31-
app.code.waitAndClick('a[aria-label="Remove connection from history"]');
33+
app.workbench.positronConnections.removeConnectionButton.click();
3234

3335
});
3436

@@ -44,27 +46,15 @@ export function setup(logger: Logger) {
4446
console.log('Opening connections pane');
4547
await app.workbench.positronVariables.doubleClickVariableRow('conn');
4648

47-
await app.code.waitAndClick('div[aria-label="SQLite Connection"]');
48-
49-
await app.code.waitAndClick('div[aria-label="main"]');
49+
await app.workbench.positronConnections.openPythonTable();
5050

5151
// click in reverse order to avoid scrolling issues
52-
await app.code.waitAndClick('div[aria-label="tracks"]');
53-
await app.code.waitAndClick('div[aria-label="playlist_track"]');
54-
await app.code.waitAndClick('div[aria-label="playlists"]');
55-
await app.code.waitAndClick('div[aria-label="media_types"]');
56-
await app.code.waitAndClick('div[aria-label="invoice_items"]');
57-
await app.code.waitAndClick('div[aria-label="invoices"]');
58-
await app.code.waitAndClick('div[aria-label="genres"]');
59-
await app.code.waitAndClick('div[aria-label="employees"]');
60-
await app.code.waitAndClick('div[aria-label="customers"]');
61-
await app.code.waitAndClick('div[aria-label="artists"]');
62-
await app.code.waitAndClick('div[aria-label="albums"]');
52+
await app.workbench.positronConnections.openConnectionsNodes(tables);
6353

6454
// disconnect icon appearance requires hover
65-
await app.code.driver.getLocator('div[aria-label="SQLite Connection"]').hover();
66-
await app.code.waitAndClick('.codicon-debug-disconnect');
67-
await app.code.waitForElement('a[aria-label="Execute connection code in the console"]');
55+
await app.workbench.positronConnections.pythonConnectionOpenState.hover();
56+
await app.workbench.positronConnections.disonnectButton.click();
57+
await app.workbench.positronConnections.reconnectButton.waitforVisible();
6858
});
6959
});
7060

@@ -84,7 +74,7 @@ export function setup(logger: Logger) {
8474
after(async function () {
8575

8676
const app = this.app as Application;
87-
app.code.waitAndClick('a[aria-label="Remove connection from history"]');
77+
app.workbench.positronConnections.removeConnectionButton.click();
8878

8979
});
9080

@@ -98,33 +88,17 @@ export function setup(logger: Logger) {
9888
await app.workbench.quickaccess.runCommand('r.sourceCurrentFile');
9989

10090
console.log('Opening connections pane');
101-
await app.code.waitAndClick('a[aria-label="Connections"]');
102-
103-
// not working due to timing:
104-
// await app.code.waitAndClick('div[aria-label="SQLiteConnection"]');
105-
// workaround for above:
106-
await app.code.driver.getLocator('a:has-text("SQLiteConnection")').click();
91+
await app.workbench.positronConnections.connectionsTabLink.click();
10792

108-
await app.code.waitAndClick('div[aria-label="SQLiteConnection"]:last-child');
109-
await app.code.waitAndClick('div[aria-label="Default"]');
93+
await app.workbench.positronConnections.openRTable();
11094

11195
// click in reverse order to avoid scrolling issues
112-
await app.code.waitAndClick('div[aria-label="tracks"]');
113-
await app.code.waitAndClick('div[aria-label="playlist_track"]');
114-
await app.code.waitAndClick('div[aria-label="playlists"]');
115-
await app.code.waitAndClick('div[aria-label="media_types"]');
116-
await app.code.waitAndClick('div[aria-label="invoice_items"]');
117-
await app.code.waitAndClick('div[aria-label="invoices"]');
118-
await app.code.waitAndClick('div[aria-label="genres"]');
119-
await app.code.waitAndClick('div[aria-label="employees"]');
120-
await app.code.waitAndClick('div[aria-label="customers"]');
121-
await app.code.waitAndClick('div[aria-label="artists"]');
122-
await app.code.waitAndClick('div[aria-label="albums"]');
96+
await app.workbench.positronConnections.openConnectionsNodes(tables);
12397

12498
// disconnect icon appearance requires hover
125-
await app.code.driver.getLocator('div[aria-label="SQLiteConnection"]:first-child').hover();
126-
await app.code.waitAndClick('.codicon-debug-disconnect');
127-
await app.code.waitForElement('a[aria-label="Execute connection code in the console"]');
99+
await app.workbench.positronConnections.rConnectionOpenState.hover();
100+
await app.workbench.positronConnections.disonnectButton.click();
101+
await app.workbench.positronConnections.reconnectButton.waitforVisible();
128102
});
129103
});
130104
});

0 commit comments

Comments
 (0)