Skip to content

Commit 1856215

Browse files
authored
e2e-test: update session tests (#6567)
### Summary Sessions tests broke when the power button was removed. Updated tests to be able to handle this. ### QA Notes @:sessions
1 parent 4a4d941 commit 1856215

File tree

2 files changed

+41
-37
lines changed

2 files changed

+41
-37
lines changed

test/e2e/pages/sessions.ts

+31-17
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,22 @@ export class Sessions {
205205
await this.page.keyboard.press('Escape');
206206
}
207207

208+
/**
209+
* Action: Delete all disconnected sessions
210+
*/
211+
async deleteDisconnectedSessions() {
212+
await test.step('Delete all disconnected sessions', async () => {
213+
const sessionIds = await this.getAllSessionIds();
214+
215+
for (const sessionId of sessionIds) {
216+
const status = await this.getStatus(sessionId);
217+
if (status === 'disconnected') {
218+
await this.delete(sessionId);
219+
}
220+
}
221+
});
222+
}
223+
208224
// -- Helpers --
209225

210226
/**
@@ -224,24 +240,22 @@ export class Sessions {
224240
* @returns id of the session
225241
*/
226242
async reuseSessionIfExists(session: SessionInfo): Promise<string> {
227-
const sessionLocator = this.getSessionTab(session.name);
228-
const sessionExists = await sessionLocator.isVisible();
229-
230-
if (sessionExists) {
231-
await sessionLocator.click();
232-
const status = await this.getStatus(session.name);
233-
let sessionId = await this.getCurrentSessionId();
234-
235-
if (status === 'idle') {
236-
return sessionId;
237-
} else if (status === 'disconnected') {
238-
sessionId = await this.start(session.name);
239-
return sessionId;
243+
return await test.step(`Reuse session: ${session.name}`, async () => {
244+
const sessionLocator = this.getSessionTab(session.name);
245+
const sessionExists = await sessionLocator.isVisible();
246+
247+
if (sessionExists) {
248+
await sessionLocator.click();
249+
const status = await this.getStatus(session.name);
250+
251+
if (status === 'idle') {
252+
return await this.getCurrentSessionId();
253+
}
240254
}
241-
}
242255

243-
// Create a new session if none exists
244-
return await this.launch(session);
256+
// Create a new session if none exists
257+
return await this.launch(session);
258+
});
245259
}
246260

247261
/**
@@ -347,7 +361,7 @@ export class Sessions {
347361
* @returns the metadata of the session
348362
*/
349363
async getMetadata(sessionId?: string): Promise<SessionMetaData> {
350-
return await test.step(`Get metadata for session: ${sessionId}`, async () => {
364+
return await test.step(`Get metadata for session: ${sessionId ?? 'current tab'}`, async () => {
351365
if (sessionId) {
352366
await this.page.getByTestId(`console-tab-${sessionId}`).click();
353367
}

test/e2e/tests/sessions/sessions.test.ts

+10-20
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ test.use({
2222
suiteId: __filename
2323
});
2424

25-
test.describe.skip('Sessions', {
25+
test.describe('Sessions', {
2626
tag: [tags.WIN, tags.WEB, tags.CONSOLE, tags.SESSIONS]
2727
}, () => {
2828

@@ -35,21 +35,15 @@ test.describe.skip('Sessions', {
3535
});
3636

3737
test.afterEach(async function ({ app }) {
38-
const sessionIds = await app.workbench.sessions.getAllSessionIds();
39-
sessionIds.map(async sessionId => {
40-
const status = await app.workbench.sessions.getStatus(sessionId);
41-
if (status === 'disconnected') {
42-
await app.workbench.sessions.delete(sessionId);
43-
}
44-
});
38+
await app.workbench.sessions.deleteDisconnectedSessions();
4539
});
4640

4741
test('Validate state between sessions (active, idle, disconnect) ', async function ({ app }) {
4842
const sessions = app.workbench.sessions;
4943
const console = app.workbench.console;
5044

5145
// Start Python session
52-
pythonSession.id = await app.workbench.sessions.launch({ ...pythonSession, waitForReady: false });
46+
pythonSession.id = await sessions.launch({ ...pythonSession, waitForReady: false });
5347

5448
// Verify Python session is visible and transitions from active --> idle
5549
await sessions.expectStatusToBe(pythonSession.id, 'active');
@@ -61,7 +55,7 @@ test.describe.skip('Sessions', {
6155
await sessions.expectStatusToBe(pythonSession.id, 'idle');
6256

6357
// Start R session
64-
rSession.id = await app.workbench.sessions.launch({ ...rSession, waitForReady: false });
58+
rSession.id = await sessions.launch({ ...rSession, waitForReady: false });
6559

6660
// Verify R session transitions from active --> idle while Python session remains idle
6761
await sessions.expectStatusToBe(rSession.id, 'active');
@@ -92,9 +86,8 @@ test.describe.skip('Sessions', {
9286
const console = app.workbench.console;
9387

9488
// Start Python and R sessions
95-
rSession.id = await app.workbench.sessions.reuseSessionIfExists(rSession);
96-
pythonSession.id = await app.workbench.sessions.reuseSessionIfExists(pythonSession);
97-
89+
pythonSession.id = await sessions.reuseSessionIfExists(pythonSession);
90+
rSession.id = await sessions.reuseSessionIfExists(rSession);
9891

9992
// Verify Python session transitions to active when executing code
10093
await sessions.select(pythonSession.name);
@@ -179,11 +172,7 @@ test.describe.skip('Sessions', {
179172
await variables.expectVariableToBe('z', '4');
180173
});
181174

182-
test('Validate active session list in console matches active session list in session picker', {
183-
annotation: [
184-
{ type: 'issue', description: 'sessions are not correctly sorted atm. see line 174.' }
185-
]
186-
}, async function ({ app }) {
175+
test('Validate active session list in console matches active session list in session picker', async function ({ app }) {
187176
const sessions = app.workbench.sessions;
188177
const console = app.workbench.console;
189178

@@ -205,8 +194,9 @@ test.describe.skip('Sessions', {
205194
await sessions.expectSessionCountToBe(0, 'active');
206195
await sessions.expectSessionListsToMatch();
207196

208-
// Start Python session (again) and verify active sessions
209-
await sessions.start(pythonSession.name);
197+
// Launch Python session (again) and verify active sessions
198+
await sessions.deleteDisconnectedSessions();
199+
await sessions.launch(pythonSession);
210200
await sessions.expectSessionCountToBe(1, 'active');
211201
await sessions.expectSessionListsToMatch();
212202

0 commit comments

Comments
 (0)