Skip to content

Commit 00d14e2

Browse files
authored
Fix e2e tests (#4106)
* attempt to scroll to the bottom of the SCM view * try using the arrow keys to bring items into view * tidy up util code
1 parent e78babd commit 00d14e2

File tree

2 files changed

+77
-45
lines changed

2 files changed

+77
-45
lines changed

extension/src/test/e2e/extension.test.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {
44
closeAllEditors,
55
createCustomPlot,
66
deleteAllExistingExperiments,
7-
deleteCustomPlot,
7+
deleteCustomPlots,
88
dismissAllNotifications,
99
expectAllPlotsToBeFilled,
1010
findDecorationTooltip,
@@ -29,9 +29,7 @@ before('should finish loading the extension', async function () {
2929
after(async function () {
3030
this.timeout(60000)
3131

32-
try {
33-
await deleteCustomPlot()
34-
} catch {}
32+
await deleteCustomPlots()
3533
await dismissAllNotifications()
3634

3735
return waitForDvcToFinish()
@@ -175,7 +173,7 @@ describe('Plots Webview', function () {
175173
await webview.unfocus()
176174
await closeAllEditors()
177175

178-
await deleteCustomPlot()
176+
await deleteCustomPlots()
179177
await workbench.executeCommand('DVC: Show Plots')
180178

181179
await waitForDvcToFinish()
@@ -230,12 +228,16 @@ describe('Source Control View', function () {
230228
const tooltip = await findDecorationTooltip(treeItem)
231229
expect(tooltip).toBeTruthy()
232230
}
233-
return dvcTreeItemLabels.length > 0
231+
return expectedScmItemLabels.length === dvcTreeItemLabels.length
234232
},
235233
{
236234
interval: 5000,
237235
timeout: 60000
238236
}
239237
)
238+
239+
expectedScmItemLabels.sort()
240+
dvcTreeItemLabels.sort()
241+
expect(expectedScmItemLabels).toStrictEqual(dvcTreeItemLabels)
240242
})
241243
})

extension/src/test/e2e/util.ts

Lines changed: 69 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Key } from 'webdriverio'
22
import { $$, browser } from '@wdio/globals'
3-
import { ViewControl } from 'wdio-vscode-service'
3+
import { ViewControl, Workbench } from 'wdio-vscode-service'
44
import { PlotsWebview } from './pageObjects/plotsWebview.js'
55

66
const findProgressBars = () => $$('.monaco-progress-container')
@@ -17,8 +17,8 @@ export const dismissAllNotifications = async (): Promise<void> => {
1717
await browser.waitUntil(async () => {
1818
const workbench = await browser.getWorkbench()
1919
const notifications = await workbench.getNotifications()
20-
for (const n of notifications) {
21-
await n.dismiss()
20+
for (const notification of notifications) {
21+
await notification.dismiss()
2222
}
2323
const openNotifications = await workbench.getNotifications()
2424
return openNotifications.length === 0
@@ -35,6 +35,50 @@ const dvcIsWorking = async (): Promise<boolean> => {
3535
)
3636
}
3737

38+
const notificationShown = async (
39+
workbench: Workbench,
40+
message: string
41+
): Promise<boolean> => {
42+
const notifications = await workbench.getNotifications()
43+
return notifications.some(
44+
async notification => (await notification.elem.getText()) === message
45+
)
46+
}
47+
48+
const runDeleteCommand = async (
49+
command: string,
50+
nothingToDeleteMessage: string
51+
): Promise<void> => {
52+
const workbench = await browser.getWorkbench()
53+
const commandPalette = await workbench.executeCommand(command)
54+
55+
let nothingToDelete = false
56+
57+
await browser.waitUntil(async () => {
58+
if (await notificationShown(workbench, nothingToDeleteMessage)) {
59+
nothingToDelete = true
60+
return true
61+
}
62+
63+
return commandPalette.elem.isDisplayed()
64+
})
65+
66+
if (nothingToDelete) {
67+
return
68+
}
69+
await browser
70+
.action('key')
71+
.down(Key.Shift)
72+
.down(Key.Tab)
73+
.up(Key.Tab)
74+
.up(Key.Shift)
75+
.perform()
76+
77+
await browser.keys('Space')
78+
79+
return browser.keys('Enter')
80+
}
81+
3882
export const waitForDvcToFinish = async (timeout = 60000): Promise<void> => {
3983
await browser.waitUntil(async () => !(await dvcIsWorking()), {
4084
timeout
@@ -100,32 +144,12 @@ export const waitForViewContainerToLoad = async (): Promise<void> => {
100144
)
101145
}
102146

103-
export const deleteAllExistingExperiments = async () => {
104-
const workbench = await browser.getWorkbench()
105-
106-
const deleteNonWorkspaceExperiments = await workbench.executeCommand(
107-
'DVC: Remove Experiment(s)'
147+
export const deleteAllExistingExperiments = (): Promise<void> =>
148+
runDeleteCommand(
149+
'DVC: Remove Experiment(s)',
150+
'There are no experiments to select.'
108151
)
109152

110-
try {
111-
await browser.waitUntil(() =>
112-
deleteNonWorkspaceExperiments.elem.isDisplayed()
113-
)
114-
115-
await browser
116-
.action('key')
117-
.down(Key.Shift)
118-
.down(Key.Tab)
119-
.up(Key.Tab)
120-
.up(Key.Shift)
121-
.perform()
122-
123-
await browser.keys('Space')
124-
125-
return browser.keys('Enter')
126-
} catch {}
127-
}
128-
129153
export const runModifiedExperiment = async () => {
130154
const workbench = await browser.getWorkbench()
131155
const options = await workbench.executeCommand(
@@ -142,7 +166,10 @@ export const runModifiedExperiment = async () => {
142166
.up(Key.Enter)
143167
.pause(100)
144168
.perform()
145-
await browser.keys([...'0.005', 'Enter'])
169+
170+
const nonCachedParam = `0.00${Date.now()}`
171+
172+
await browser.keys([...nonCachedParam, 'Enter'])
146173
return workbench.executeCommand('DVC: Show Experiments')
147174
}
148175

@@ -161,16 +188,11 @@ export const createCustomPlot = async (): Promise<void> => {
161188
return browser.keys('Enter')
162189
}
163190

164-
export const deleteCustomPlot = async (): Promise<void> => {
165-
const workbench = await browser.getWorkbench()
166-
const removeCustomPlot = await workbench.executeCommand(
167-
'DVC: Remove Custom Plot(s)'
191+
export const deleteCustomPlots = (): Promise<void> =>
192+
runDeleteCommand(
193+
'DVC: Remove Custom Plot(s)',
194+
'There are no plots to remove.'
168195
)
169-
await browser.waitUntil(() => removeCustomPlot.elem.isDisplayed())
170-
await browser.keys('ArrowDown')
171-
await browser.keys('Space')
172-
return browser.keys('Enter')
173-
}
174196

175197
export const waitForAllPlotsToRender = (
176198
webview: PlotsWebview,
@@ -193,11 +215,19 @@ export const expectAllPlotsToBeFilled = async (webview: PlotsWebview) => {
193215
}
194216

195217
export const findScmTreeItems = async () => {
196-
const workspace = await browser.getWorkbench()
197-
const activityBar = workspace.getActivityBar()
218+
const workbench = await browser.getWorkbench()
219+
const activityBar = workbench.getActivityBar()
198220
const sourceControlIcon = await activityBar.getViewControl('Source Control')
199221

200222
await sourceControlIcon?.openView()
201223

224+
const visibleItems = await findCurrentTreeItems()
225+
226+
await visibleItems[visibleItems.length - 1].click()
227+
228+
for (let i = 0; i < 20; i++) {
229+
await browser.keys('ArrowDown')
230+
}
231+
202232
return findCurrentTreeItems()
203233
}

0 commit comments

Comments
 (0)