-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathindex.ts
More file actions
123 lines (111 loc) · 4.21 KB
/
index.ts
File metadata and controls
123 lines (111 loc) · 4.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
import { DefaultTreeSection } from 'wdio-vscode-service'
import type { StatusStrings } from 'assertions/index.ts'
import type { TreeItem, Workbench, ViewControl, ViewContent, ViewItemAction, ViewTitlePart } from 'wdio-vscode-service'
export { STATUS } from './constants.js'
export async function openTestingView(workbench: Workbench) {
const activityBar = workbench.getActivityBar()
let testingViewControl: ViewControl | undefined
await browser.waitUntil(
async () => {
testingViewControl = await activityBar.getViewControl('Testing')
return typeof testingViewControl !== 'undefined'
},
{
timeoutMsg: 'Testing view was not opened',
}
)
await testingViewControl!.openView()
return testingViewControl!
}
export async function getTestingSection(content: ViewContent) {
return new DefaultTreeSection(content.locatorMap, content.section$, content)
}
export async function waitForResolved(browser: WebdriverIO.Browser, item: TreeItem) {
await browser.waitUntil(
async () => {
const regex = new RegExp('Resolving WebdriverIO Tests')
return !regex.test(await item.getLabel())
},
{
timeoutMsg: 'Resolving tests ware not finished',
}
)
}
export async function clickTreeItemButton(browser: WebdriverIO.Browser, target: TreeItem, buttonLabel: string) {
let btn: ViewItemAction | undefined
await browser.waitUntil(
async () => {
btn = await target.getActionButton(buttonLabel)
if (btn && (await (btn.elem as WebdriverIO.Element).isClickable())) {
return true
}
return false
},
{
timeoutMsg: 'The button is not clickable.',
}
)
await (btn!.elem as WebdriverIO.Element).click()
}
export async function waitForTestStatus(browser: WebdriverIO.Browser, item: TreeItem, status: StatusStrings) {
await browser.waitUntil(
async () => {
const label = await item.getLabel()
// wdio.conf.ts (Passed), in 3.2s
const matcherResult = label.match(/\(([^)]+)\), in .*s$/)
return matcherResult && matcherResult[1] === status
},
{
timeout: 180000,
timeoutMsg: `expected status(${status}) to be different(current: ${await item.getLabel()})`,
}
)
}
export async function clearAllTestResults(workbench: Workbench) {
const notifications = await workbench.getNotifications()
await Promise.all(
notifications.map(async (notification) => {
return await notification.dismiss()
})
)
const bottomBarPanel = workbench.getBottomBar()
const tabTitle = 'Test Results'
try {
const tabContainer = await bottomBarPanel.tabContainer$
const tab = (await tabContainer.$(`.//a[starts-with(@aria-label, '${tabTitle}')]`)) as WebdriverIO.Element
if (await tab.isExisting()) {
await tab.click()
await bottomBarPanel.elem
.$(
(bottomBarPanel.locatorMap.BottomBarViews.actionsContainer as Function)(
'Test Results actions'
) as string
)
.$(bottomBarPanel.locatorMap.BottomBarViews.clearText as string)
.click()
}
} catch (_error) {
console.log(_error)
}
}
export async function clickTitleActionButton(titlePart: ViewTitlePart, label: string | RegExp) {
const elements = (await titlePart.elem.$$(
(titlePart.locatorMap.ViewSection.actionConstructor as Function)()
)) as WebdriverIO.Element[]
const regExp = typeof label === 'string' ? new RegExp(label) : label
for (const element of elements) {
const actualLabel = await element.getAttribute('aria-label')
if (regExp.test(actualLabel)) {
await element.click()
break
}
}
}
export async function collapseAllTests(testingSection: DefaultTreeSection) {
const items = (await testingSection.getVisibleItems()).reverse()
for (const item of items) {
if ((await item.isExpandable()) && (await item.isExpanded())) {
await item.collapse()
}
}
}