-
Notifications
You must be signed in to change notification settings - Fork 20
/
AbstractViews.ts
102 lines (92 loc) · 3.5 KB
/
AbstractViews.ts
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
import { ElementWithContextMenu } from '../utils.js'
/**
* View with channel selector/**
*
* @category BottomBar
*/
export abstract class ChannelView<T> extends ElementWithContextMenu<T> {
protected actionsLabel!: string
/**
* Get names of all selectable channels
* @returns Promise resolving to array of strings - channel names
*/
async getChannelNames (): Promise<string[]> {
// stabilize view otherwise we might run into stale element issues
// eslint-disable-next-line wdio/no-pause
await browser.pause(500)
const select = await this.parent.$(this.locatorMap.BottomBarViews.outputChannels as string)
await select.click()
// stabilize view otherwise we might run into stale element issues
// eslint-disable-next-line wdio/no-pause
await browser.pause(500)
const channels = await this.parent.$$(`${this.locatorMap.BottomBarViews.outputChannels} option`)
const names = []
for (const channel of channels) {
names.push(await channel.getAttribute('value'))
}
return names
}
/**
* Get name of the current channel
* @returns Promise resolving to the current channel name
*/
async getCurrentChannel (): Promise<string> {
const combo = await this.parent.$(this.locatorMap.BottomBarViews.channelCombo as string)
return combo.getAttribute('title')
}
/**
* Select a channel using the selector combo
* @param name name of the channel to open
*/
async selectChannel (name: string): Promise<void> {
const select = await this.parent.$(this.locatorMap.BottomBarViews.outputChannels as string)
await select.click()
const channels = await this.parent.$$(`${this.locatorMap.BottomBarViews.outputChannels} option`)
for (const channel of channels) {
const val = await channel.getValue()
if (val === name) {
await channel.click()
// eslint-disable-next-line wdio/no-pause
await browser.pause(200)
await browser.keys(['Escape'])
return
}
}
throw new Error(`Channel ${name} not found`)
}
}
/**
* View with channel selection and text area
*/
export abstract class TextView<T> extends ChannelView<T> {
protected actionsLabel!: string
/**
* Get all text from the currently open channel
* @returns Promise resolving to the view's text
*/
async getText (): Promise<string[]> {
const lines = await this.elem.$(this.locatorMap.OutputView.lines as string)
const textLines = await browser.execute(
(elem) => Array.from(
(elem as any as HTMLDivElement).children as any as ArrayLike<HTMLDivElement>
).map((l) => l.innerText),
lines
)
return textLines
// strip empty lines (usually the last one)
.filter(Boolean)
// replace `\u00A0` characters with white space
// eslint-disable-next-line no-control-regex
.map((l) => l.replace(/\u00A0/g, ' '))
}
/**
* Clear the text in the current channel
* @returns Promise resolving when the clear text button is pressed
*/
async clearText (): Promise<void> {
await this.parent
.$((this.locatorMap.BottomBarViews.actionsContainer as Function)(this.actionsLabel) as string)
.$(this.locatorMap.BottomBarViews.clearText as string)
.click()
}
}