@winning-test/component 0.0.102 → 0.0.104
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/rfds5.6/component/BlockComponent.js +264 -0
- package/rfds5.6/component/ButtonComponent.js +23 -0
- package/rfds5.6/component/CanvasComponent.js +36 -0
- package/rfds5.6/component/CheckboxComponent.js +53 -0
- package/rfds5.6/component/Component.js +93 -0
- package/rfds5.6/component/DialogComponent.js +23 -0
- package/rfds5.6/component/InputComponent.js +31 -0
- package/rfds5.6/component/ListComponent.js +53 -0
- package/rfds5.6/component/ListCompositeComponent.js +93 -0
- package/rfds5.6/component/MessageComponent.js +23 -0
- package/rfds5.6/component/RadioComponent.js +44 -0
- package/rfds5.6/component/SelectComponent.js +77 -0
- package/rfds5.6/component/SelectCompositeComponent.js +46 -0
- package/rfds5.6/component/SwitchComponent.js +50 -0
- package/rfds5.6/component/TableComponent.js +113 -0
- package/rfds5.6/component/TextComponent.js +23 -0
- package/rfds5.6/component/TextareaComponent.js +27 -0
- package/rfds5.6/page/Page.js +230 -0
- package/rfds5.6/test/component.test.js +64 -0
- package/rfds5.6/test/component.test.json +13 -0
package/package.json
CHANGED
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 块组件类
|
|
3
|
+
* @作者 MaoJJ
|
|
4
|
+
*/
|
|
5
|
+
class BlockComponent extends require("./Component") {
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 块组件
|
|
9
|
+
* @param {Browser} browser
|
|
10
|
+
* @param {String} xpath xpath
|
|
11
|
+
*/
|
|
12
|
+
constructor(browser, xpath) {
|
|
13
|
+
super(browser);
|
|
14
|
+
this.xpath = xpath;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
_createXpath() {
|
|
18
|
+
return this.xpath;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* 获取块组件
|
|
23
|
+
* @param {String} id id
|
|
24
|
+
* @param {String} xpath xpath
|
|
25
|
+
* @returns 块组件
|
|
26
|
+
*/
|
|
27
|
+
blockComponent(id, xpath) {
|
|
28
|
+
let that = this;
|
|
29
|
+
class _BlockComponent extends BlockComponent {
|
|
30
|
+
_createRootXpath() {
|
|
31
|
+
return that.getXpath();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return new _BlockComponent(this.browser, id, xpath);
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 获取按钮组件
|
|
39
|
+
* @param {String} text 文本
|
|
40
|
+
* @returns 按钮组件
|
|
41
|
+
*/
|
|
42
|
+
buttonComponent(text) {
|
|
43
|
+
let that = this;
|
|
44
|
+
class ButtonComponent extends require("./ButtonComponent") {
|
|
45
|
+
_createRootXpath() {
|
|
46
|
+
return that.getXpath();
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return new ButtonComponent(this.browser, text);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 获取复选框组件
|
|
54
|
+
* @param {String} label 标签
|
|
55
|
+
* @returns 复选框组件
|
|
56
|
+
*/
|
|
57
|
+
checkboxComponent(label) {
|
|
58
|
+
let that = this;
|
|
59
|
+
class CheckboxComponent extends require("./CheckboxComponent") {
|
|
60
|
+
_createRootXpath() {
|
|
61
|
+
return that.getXpath();
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return new CheckboxComponent(this.browser, label);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* 获取画图板组件
|
|
69
|
+
* @returns 画图板组件
|
|
70
|
+
*/
|
|
71
|
+
canvasComponent() {
|
|
72
|
+
let that = this;
|
|
73
|
+
class CanvasComponent extends require("./CanvasComponent") {
|
|
74
|
+
_createRootXpath() {
|
|
75
|
+
return that.getXpath();
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return new CanvasComponent(this.browser);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* 获取对话框组件
|
|
83
|
+
* @param {String} title 标题
|
|
84
|
+
* @returns 对话框组件
|
|
85
|
+
*/
|
|
86
|
+
dialogComponent(title) {
|
|
87
|
+
let that = this;
|
|
88
|
+
class DialogComponent extends require("./DialogComponent") {
|
|
89
|
+
_createRootXpath() {
|
|
90
|
+
return that.getXpath();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
return new DialogComponent(this.browser, title);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* 获取输入框组件
|
|
98
|
+
* @param {String} placeholder 背景文字
|
|
99
|
+
* @param {String} label 标签
|
|
100
|
+
* @returns 输入框组件
|
|
101
|
+
*/
|
|
102
|
+
inputComponent(placeholder, label) {
|
|
103
|
+
let that = this;
|
|
104
|
+
class InputComponent extends require("./InputComponent") {
|
|
105
|
+
_createRootXpath() {
|
|
106
|
+
return that.getXpath();
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
return new InputComponent(this.browser, placeholder, label);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* 获取列表组件
|
|
115
|
+
* @returns 列表组件
|
|
116
|
+
*/
|
|
117
|
+
listComponent() {
|
|
118
|
+
let that = this;
|
|
119
|
+
class ListComponent extends require("./ListComponent") {
|
|
120
|
+
_createRootXpath() {
|
|
121
|
+
return that.getXpath();
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return new ListComponent(this.browser);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* 获取复合列表组件
|
|
129
|
+
* @returns 列表组件
|
|
130
|
+
*/
|
|
131
|
+
listCompositeComponent() {
|
|
132
|
+
let that = this;
|
|
133
|
+
class ListCompositeComponent extends require("./ListCompositeComponent") {
|
|
134
|
+
_createRootXpath() {
|
|
135
|
+
return that.getXpath();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
return new ListCompositeComponent(this.browser);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* 获取消息组件
|
|
143
|
+
* @param {Stirng} text 文本
|
|
144
|
+
* @returns 消息组件
|
|
145
|
+
*/
|
|
146
|
+
messageComponent(text) {
|
|
147
|
+
let that = this;
|
|
148
|
+
class MessageComponent extends require("./MessageComponent") {
|
|
149
|
+
_createRootXpath() {
|
|
150
|
+
return that.getXpath();
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
return new MessageComponent(this.browser, text);
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* 获取单选组件
|
|
158
|
+
* @param {Stirng} label 标签
|
|
159
|
+
* @returns 单选组件
|
|
160
|
+
*/
|
|
161
|
+
radioComponent(label) {
|
|
162
|
+
let that = this;
|
|
163
|
+
class RadioComponent extends require("./RadioComponent") {
|
|
164
|
+
_createRootXpath() {
|
|
165
|
+
return that.getXpath();
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return new RadioComponent(this.browser, label);
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* 获取选择器组件
|
|
173
|
+
* @param {String} placeholder 背景文字
|
|
174
|
+
* @param {String} label 标签
|
|
175
|
+
* @returns 选择器组件
|
|
176
|
+
*/
|
|
177
|
+
selectComponent(placeholder, label, forceMulti) {
|
|
178
|
+
let that = this;
|
|
179
|
+
class SelectComponent extends require("./SelectComponent") {
|
|
180
|
+
_createRootXpath() {
|
|
181
|
+
return that.getXpath();
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return new SelectComponent(this.browser, placeholder, label, forceMulti);
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* 获取复合选择器组件
|
|
189
|
+
* @param {String} placeholder 背景文字
|
|
190
|
+
* @param {String} label 标签
|
|
191
|
+
* @returns 选择器组件
|
|
192
|
+
*/
|
|
193
|
+
selectCompositeComponent(placeholder, label) {
|
|
194
|
+
let that = this;
|
|
195
|
+
class SelectCompositeComponent extends require("./SelectCompositeComponent") {
|
|
196
|
+
_createRootXpath() {
|
|
197
|
+
return that.getXpath();
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
return new SelectCompositeComponent(this.browser, placeholder, label);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* 获取开关组件
|
|
205
|
+
* @param {String} label 标签
|
|
206
|
+
* @returns 开关组件
|
|
207
|
+
*/
|
|
208
|
+
switchComponent(label) {
|
|
209
|
+
let that = this;
|
|
210
|
+
class SwitchComponent extends require("./SwitchComponent") {
|
|
211
|
+
_createRootXpath() {
|
|
212
|
+
return that.getXpath();
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
return new SwitchComponent(this.browser, label);
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* 获取表格组件
|
|
220
|
+
* @returns 表格组件
|
|
221
|
+
*/
|
|
222
|
+
tableComponent() {
|
|
223
|
+
let that = this;
|
|
224
|
+
class TableComponent extends require("./TableComponent") {
|
|
225
|
+
_createRootXpath() {
|
|
226
|
+
return that.getXpath();
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return new TableComponent(this.browser);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* 获取多行文本输入组件
|
|
234
|
+
* @param {String} textarea 多行文本输入
|
|
235
|
+
* @returns 多行文本输入组件
|
|
236
|
+
*/
|
|
237
|
+
textareaComponent(placeholder, label) {
|
|
238
|
+
let that = this;
|
|
239
|
+
class TextareaComponent extends require("./TextareaComponent") {
|
|
240
|
+
_createRootXpath() {
|
|
241
|
+
return that.getXpath();
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
return new TextareaComponent(this.browser, placeholder, label);
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* 获取文本组件
|
|
249
|
+
* @param {String} text 文本
|
|
250
|
+
* @returns 文本组件
|
|
251
|
+
*/
|
|
252
|
+
textComponent(text) {
|
|
253
|
+
let that = this;
|
|
254
|
+
class TextComponent extends require("./TextComponent") {
|
|
255
|
+
_createRootXpath() {
|
|
256
|
+
return that.getXpath();
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
return new TextComponent(this.browser, text);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
module.exports = BlockComponent;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 按钮组件类
|
|
3
|
+
* @作者 MaoJJ
|
|
4
|
+
*/
|
|
5
|
+
class ButtonComponent extends require("./Component") {
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 按钮组件
|
|
9
|
+
* @param {Browser} browser 浏览器
|
|
10
|
+
* @param {String} text 文本
|
|
11
|
+
*/
|
|
12
|
+
constructor(browser, text) {
|
|
13
|
+
super(browser);
|
|
14
|
+
this.text = text;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
_createXpath() {
|
|
18
|
+
return `//*[normalize-space(text())='${this.text}']/ancestor-or-self::button`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = ButtonComponent;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 画图板组件类
|
|
3
|
+
* @作者 MaoJJ
|
|
4
|
+
*/
|
|
5
|
+
class CanvasComponent extends require("./Component") {
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 画图板组件
|
|
9
|
+
* @param {Browser} browser 浏览器
|
|
10
|
+
*/
|
|
11
|
+
constructor(browser) {
|
|
12
|
+
super(browser);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
_createXpath() {
|
|
16
|
+
return "//canvas";
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 随便画个圆,想画别的可以用js自己定制。
|
|
21
|
+
*/
|
|
22
|
+
async draw() {
|
|
23
|
+
let script = `let canvas = arguments[0];
|
|
24
|
+
let ctx = canvas.getContext("2d");
|
|
25
|
+
ctx.fillStyle = "black";
|
|
26
|
+
ctx.beginPath();
|
|
27
|
+
ctx.arc(100, 100, 50, 0, Math.PI * 2);
|
|
28
|
+
ctx.lineWidth = 5;
|
|
29
|
+
ctx.stroke();`;
|
|
30
|
+
let webElement = (await this.browser.findElement(this.getXpath())).webElement;
|
|
31
|
+
await this.browser.webDriver.executeScript(script, webElement);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = CanvasComponent;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 复选框组件类
|
|
3
|
+
* @作者 MaoJJ
|
|
4
|
+
*/
|
|
5
|
+
class CheckboxComponent extends require("./Component") {
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 复选框组件
|
|
9
|
+
* @param {Browser} browser 浏览器
|
|
10
|
+
* @param {String} label 标签
|
|
11
|
+
*/
|
|
12
|
+
constructor(browser, label) {
|
|
13
|
+
super(browser);
|
|
14
|
+
this.label = label;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
_createXpath() {
|
|
18
|
+
if (this.label) {
|
|
19
|
+
return `//*[normalize-space(text())='${this.label}']/..//input[@type='checkbox']`;
|
|
20
|
+
}
|
|
21
|
+
return "//input[@type='checkbox']";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* 选择
|
|
26
|
+
*/
|
|
27
|
+
async select() {
|
|
28
|
+
if (!(await (await this.browser.findElement(this.getXpath())).isSelected())) {
|
|
29
|
+
await (await this.browser.findElement(this.getXpath())).click();
|
|
30
|
+
await this.browser.sleep(CheckboxComponent.delayTime);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 取消选择
|
|
36
|
+
*/
|
|
37
|
+
async unselect() {
|
|
38
|
+
if (await (await this.browser.findElement(this.getXpath())).isSelected()) {
|
|
39
|
+
await (await this.browser.findElement(this.getXpath())).click();
|
|
40
|
+
await this.browser.sleep(CheckboxComponent.delayTime);
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 选择状态
|
|
46
|
+
*/
|
|
47
|
+
async isSelected() {
|
|
48
|
+
return await (await this.browser.findElement(this.getXpath())).isSelected();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports = CheckboxComponent;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 组件类
|
|
3
|
+
* @作者 MaoJJ
|
|
4
|
+
*/
|
|
5
|
+
class Component extends require("@winning-test/autotest-webui/src/Component") {
|
|
6
|
+
|
|
7
|
+
static delayTime = 200;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 组件
|
|
11
|
+
* @param {Browser} browser
|
|
12
|
+
*/
|
|
13
|
+
constructor(browser) {
|
|
14
|
+
super(browser)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
getXpath() {
|
|
18
|
+
return `${super.getXpath()}[not (ancestor-or-self::*[contains(@style,'display: none')])]`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
async click() {
|
|
22
|
+
await super.click();
|
|
23
|
+
await this.browser.sleep(Component.delayTime);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
async doubleClick() {
|
|
27
|
+
await super.doubleClick();
|
|
28
|
+
await this.browser.sleep(Component.delayTime);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async input(...agrs) {
|
|
32
|
+
await super.input(...agrs);
|
|
33
|
+
await this.browser.sleep(Component.delayTime);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
async clear() {
|
|
37
|
+
await super.clear();
|
|
38
|
+
await this.browser.sleep(Component.delayTime);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async getText() {
|
|
42
|
+
await this.browser.sleep(Component.delayTime);
|
|
43
|
+
return await super.getText();
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
async getValue() {
|
|
47
|
+
await this.browser.sleep(Component.delayTime);
|
|
48
|
+
return await super.getValue();
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
async getAttribute(attributeName) {
|
|
52
|
+
await this.browser.sleep(Component.delayTime);
|
|
53
|
+
return await super.getAttribute(attributeName);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async waitUntilBeDisabled() {
|
|
57
|
+
await super.waitUntilBeDisabled();
|
|
58
|
+
await this.browser.sleep(Component.delayTime);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async waitUntilBeEnabled() {
|
|
62
|
+
await super.waitUntilBeEnabled();
|
|
63
|
+
await this.browser.sleep(Component.delayTime);
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
async waitUntilBeNotVisible() {
|
|
67
|
+
await super.waitUntilBeNotVisible();
|
|
68
|
+
await this.browser.sleep(Component.delayTime);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
async waitUntilBeVisible() {
|
|
72
|
+
await super.waitUntilBeVisible();
|
|
73
|
+
await this.browser.sleep(Component.delayTime);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async waitUntilValueNotNull(count = 20) {
|
|
77
|
+
while (count > 0) {
|
|
78
|
+
const value = await this.getValue();
|
|
79
|
+
if (value) {
|
|
80
|
+
return value;
|
|
81
|
+
} else {
|
|
82
|
+
if (count > 1) {
|
|
83
|
+
count--;
|
|
84
|
+
await this.browser.sleep(500);
|
|
85
|
+
} else {
|
|
86
|
+
throw new Error('等待获取value失败');
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
module.exports = Component;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 对话框组件类
|
|
3
|
+
* @作者 MaoJJ
|
|
4
|
+
*/
|
|
5
|
+
class DialogComponent extends require("./BlockComponent") {
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 对话框组件
|
|
9
|
+
* @param {Browser} browser 浏览器
|
|
10
|
+
* @param {String} title 标题
|
|
11
|
+
*/
|
|
12
|
+
constructor(browser, title) {
|
|
13
|
+
super(browser);
|
|
14
|
+
this.title = title;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
_createXpath() {
|
|
18
|
+
return `//*[contains(normalize-space(text()),'${this.title}')]/ancestor::*[@class='w-modal' or @role='dialog']`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = DialogComponent;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 输入框组件类
|
|
3
|
+
* @作者 MaoJJ
|
|
4
|
+
*/
|
|
5
|
+
class InputComponent extends require("./Component") {
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 输入框组件
|
|
9
|
+
* @param {Browser} browser 浏览器
|
|
10
|
+
* @param {String} placeholder 背景文字
|
|
11
|
+
* @param {String} label 标签
|
|
12
|
+
*/
|
|
13
|
+
constructor(browser, placeholder, label) {
|
|
14
|
+
super(browser);
|
|
15
|
+
this.placeholder = placeholder;
|
|
16
|
+
this.label = label;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
_createXpath() {
|
|
20
|
+
if (this.placeholder) {
|
|
21
|
+
return `//input[@placeholder='${this.placeholder}']`;
|
|
22
|
+
}
|
|
23
|
+
if (this.label) {
|
|
24
|
+
return `//*[normalize-space(text())='${this.label}']/ancestor-or-self::label/..//input`;
|
|
25
|
+
}
|
|
26
|
+
return "//input[@type='text']";
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = InputComponent;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 列表组件类
|
|
3
|
+
* @作者 MaoJJ
|
|
4
|
+
*/
|
|
5
|
+
class ListComponent extends require("./Component") {
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 列表组件
|
|
9
|
+
* @param {Browser} browser 浏览器
|
|
10
|
+
*/
|
|
11
|
+
constructor(browser) {
|
|
12
|
+
super(browser);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
_createXpath() {
|
|
16
|
+
return `//ul[contains(@class, 'w-select-dropdown')]`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 选择列表
|
|
21
|
+
* @param {...String} items 列表项
|
|
22
|
+
*/
|
|
23
|
+
async select(...items) {
|
|
24
|
+
let xpath = `${this.getXpath()}`;
|
|
25
|
+
await this.browser.waitUntilElementBeVisible(xpath);
|
|
26
|
+
for (let i = 0; i < items.length; i++) {
|
|
27
|
+
let item = items[i];
|
|
28
|
+
xpath = `${this.getXpath()}//*[normalize-space(text())='${item}']/ancestor-or-self::li`;
|
|
29
|
+
await this.browser.waitUntilElementBeVisible(xpath);
|
|
30
|
+
await (await this.browser.findElement(xpath)).scrollIntoView();
|
|
31
|
+
await (await this.browser.findElement(xpath)).click();
|
|
32
|
+
await this.browser.sleep(ListComponent.delayTime);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* 获取列表项
|
|
38
|
+
* @returns 列表项
|
|
39
|
+
*/
|
|
40
|
+
async getListItems() {
|
|
41
|
+
let ret = [];
|
|
42
|
+
let xpath = `${this.getXpath()}//li`;
|
|
43
|
+
let elements = await this.browser.findElements(xpath);
|
|
44
|
+
for (let i = 0; i < elements.length; i++) {
|
|
45
|
+
let element = elements[i];
|
|
46
|
+
ret.push(await element.getText(true));
|
|
47
|
+
}
|
|
48
|
+
return ret;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
module.exports = ListComponent;
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 复合列表组件类
|
|
3
|
+
* @作者 MaoJJ
|
|
4
|
+
*/
|
|
5
|
+
class ListCompositeComponent extends require("./Component") {
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 复合列表组件
|
|
9
|
+
* @param {Browser} browser 浏览器
|
|
10
|
+
*/
|
|
11
|
+
constructor(browser) {
|
|
12
|
+
super(browser);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
_createXpath() {
|
|
16
|
+
return `//div[contains(@class, 'w-select-dropdown')]`;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* 选择列表
|
|
21
|
+
*
|
|
22
|
+
* @param {Array or Object} items 列表项
|
|
23
|
+
*
|
|
24
|
+
*/
|
|
25
|
+
async select(items) {
|
|
26
|
+
let xpath = `${this.getXpath()}`;
|
|
27
|
+
await this.browser.waitUntilElementBeVisible(xpath);
|
|
28
|
+
if(!Array.isArray(items)){
|
|
29
|
+
for(let key in items) {
|
|
30
|
+
xpath = `${this.getXpath()}//*[normalize-space(text())='${key}']/ancestor-or-self::div[1]//span[contains(@class,'is-expandable')]`;
|
|
31
|
+
let count = 3;
|
|
32
|
+
while (count > 0) {
|
|
33
|
+
await this.browser.sleep(ListCompositeComponent.delayTime);
|
|
34
|
+
if (!(await (await this.browser.findElement(xpath)).getAttribute('class')).includes('expanded')) {
|
|
35
|
+
await (await this.browser.findElement(xpath)).click();
|
|
36
|
+
} else{
|
|
37
|
+
break;
|
|
38
|
+
}
|
|
39
|
+
count --;
|
|
40
|
+
}
|
|
41
|
+
if (!(await (await this.browser.findElement(xpath)).getAttribute('class')).includes('expanded')) {
|
|
42
|
+
throw new Error(`选择${key}失败`);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
await this.selectSubitems(items[key]);
|
|
46
|
+
}
|
|
47
|
+
}else{
|
|
48
|
+
await this.selectSubitems(items);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* 选择子列表
|
|
54
|
+
*
|
|
55
|
+
* @param {...String} items 列表项
|
|
56
|
+
*
|
|
57
|
+
*/
|
|
58
|
+
async selectSubitems(items) {
|
|
59
|
+
let xpath = `${this.getXpath()}`;
|
|
60
|
+
await this.browser.waitUntilElementBeVisible(xpath);
|
|
61
|
+
for (let i = 0; i < items.length; i++) {
|
|
62
|
+
let item = items[i];
|
|
63
|
+
xpath = `${this.getXpath()}//*[normalize-space(text())='${item}']/ancestor-or-self::div[1]`;
|
|
64
|
+
await this.browser.waitUntilElementBeVisible(xpath);
|
|
65
|
+
await (await this.browser.findElement(xpath)).scrollIntoView();
|
|
66
|
+
let nodeXpath = `${xpath}//input[@type="checkbox"]`
|
|
67
|
+
if (!(await (await this.browser.findElement(nodeXpath)).isSelected())) {
|
|
68
|
+
await (await this.browser.findElement(nodeXpath)).click();
|
|
69
|
+
await this.browser.sleep(ListCompositeComponent.delayTime);
|
|
70
|
+
}
|
|
71
|
+
await this.browser.sleep(ListCompositeComponent.delayTime);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* 获取列表项
|
|
78
|
+
* @returns 列表项
|
|
79
|
+
*/
|
|
80
|
+
async getListItems() {
|
|
81
|
+
let ret = [];
|
|
82
|
+
let xpath = `${this.getXpath()}//span[@class="w-tree-node__label"]`;
|
|
83
|
+
let elements = await this.browser.findElements(xpath);
|
|
84
|
+
for (let i = 0; i < elements.length; i++) {
|
|
85
|
+
let element = elements[i];
|
|
86
|
+
ret.push(await element.getText(true));
|
|
87
|
+
}
|
|
88
|
+
return ret;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
module.exports = ListCompositeComponent;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 消息组件类
|
|
3
|
+
* @作者 MaoJJ
|
|
4
|
+
*/
|
|
5
|
+
class MeaasgeComponent extends require("./Component") {
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 消息组件
|
|
9
|
+
* @param {Browser} browser 浏览器
|
|
10
|
+
* @param {String} text 文本
|
|
11
|
+
*/
|
|
12
|
+
constructor(browser, text) {
|
|
13
|
+
super(browser);
|
|
14
|
+
this.text = text;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
_createXpath() {
|
|
18
|
+
return `//*[contains(text(),'${this.text}')]/ancestor::*[@role='alert']`
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = MeaasgeComponent;
|