@winning-test/component 0.0.78 → 0.0.80
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/lis60/component/BlockComponent.js +5 -65
- package/lis60/component/MessageComponent.js +32 -2
- package/lis60/page/Page.js +4 -42
- package/lis60/test/component.test.js +12 -10
- package/package.json +2 -2
- package/rpes5.6/component/BlockComponent.js +234 -0
- package/rpes5.6/component/ButtonComponent.js +23 -0
- package/rpes5.6/component/CheckboxComponent.js +53 -0
- package/rpes5.6/component/Component.js +77 -0
- package/rpes5.6/component/DialogComponent.js +23 -0
- package/rpes5.6/component/InputComponent.js +31 -0
- package/rpes5.6/component/ListComponent.js +53 -0
- package/rpes5.6/component/MessageComponent.js +23 -0
- package/{lis60 → rpes5.6}/component/RadioComponent.js +4 -1
- package/rpes5.6/component/SelectComponent.js +76 -0
- package/{lis60 → rpes5.6}/component/SwitchComponent.js +7 -5
- package/rpes5.6/component/TableComponent.js +104 -0
- package/rpes5.6/component/TextComponent.js +23 -0
- package/rpes5.6/component/TextareaComponent.js +27 -0
- package/rpes5.6/component/TopMenuComponent.js +33 -0
- package/rpes5.6/page/Page.js +173 -0
- package/rpes5.6/test/component.test.js +114 -0
- package/rpes5.6/test/component.test.json +13 -0
- package/rpes5.6/test/func.js +87 -0
- package/lis60/component/CascaderComponent.js +0 -51
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
|
|
77
|
+
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,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;
|
|
@@ -15,7 +15,10 @@ class RadioComponent extends require("./Component") {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
_createXpath() {
|
|
18
|
-
|
|
18
|
+
if (this.label) {
|
|
19
|
+
return `//*[normalize-space(text())='${this.label}']/..//input[@type='radio']`;
|
|
20
|
+
}
|
|
21
|
+
return "//input[@type='radio']";
|
|
19
22
|
}
|
|
20
23
|
|
|
21
24
|
/**
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 选择器组件类
|
|
3
|
+
* @作者 MaoJJ
|
|
4
|
+
*/
|
|
5
|
+
class SelectComponent 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
|
+
* @param {...String} items 选项
|
|
32
|
+
*/
|
|
33
|
+
async select(...items) {
|
|
34
|
+
let count = 2;
|
|
35
|
+
while (count > 0) {
|
|
36
|
+
try {
|
|
37
|
+
await this._select(...items);
|
|
38
|
+
if (items.length > 1){ // 多选不检查value
|
|
39
|
+
break;
|
|
40
|
+
}
|
|
41
|
+
const value = await this.getValue();
|
|
42
|
+
if (!(value && items.join().indexOf(value) !== -1)) {
|
|
43
|
+
throw new Error(`选择${items}失败`);
|
|
44
|
+
}
|
|
45
|
+
break;
|
|
46
|
+
} catch (error) {
|
|
47
|
+
if (count > 1) {
|
|
48
|
+
count--;
|
|
49
|
+
await this.browser.sleep(500);
|
|
50
|
+
} else {
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
await this.browser.sleep(SelectComponent.delayTime);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
async _select(...items) {
|
|
59
|
+
class ListComponent extends require("./ListComponent") {
|
|
60
|
+
_createXpath() {
|
|
61
|
+
return "//*[@class='w-scrollbar']"
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
let xpath = this.getXpath();
|
|
65
|
+
await (await this.browser.findElement(xpath)).click();
|
|
66
|
+
let listComponent = new ListComponent(this.browser);
|
|
67
|
+
await listComponent.select(...items);
|
|
68
|
+
if (items.length > 1) {
|
|
69
|
+
xpath = this.getXpath();
|
|
70
|
+
await (await this.browser.findElement(xpath)).click();
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
module.exports = SelectComponent;
|
|
@@ -15,20 +15,21 @@ class SwitchComponent extends require("./Component") {
|
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
_createXpath() {
|
|
18
|
-
if
|
|
19
|
-
return `//*[normalize-space(text())='${this.label}']
|
|
18
|
+
if(this.label){
|
|
19
|
+
return `//*[normalize-space(text())='${this.label}']//following-sibling::div//input[@type='checkbox']`;
|
|
20
20
|
}
|
|
21
|
-
return "
|
|
21
|
+
return "//input[@type='checkbox' and @class='w-switch__input']";
|
|
22
22
|
}
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* 打开
|
|
26
26
|
*/
|
|
27
27
|
async on() {
|
|
28
|
-
let xpath =
|
|
28
|
+
let xpath = this.getXpath();
|
|
29
29
|
let checked = Boolean(await (await this.browser.findElement(xpath)).getAttribute("checked"));
|
|
30
30
|
if (!checked) {
|
|
31
31
|
await (await this.browser.findElement(xpath)).click();
|
|
32
|
+
await this.browser.sleep(SwitchComponent.delayTime);
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
|
|
@@ -36,10 +37,11 @@ class SwitchComponent extends require("./Component") {
|
|
|
36
37
|
* 关闭
|
|
37
38
|
*/
|
|
38
39
|
async off() {
|
|
39
|
-
let xpath =
|
|
40
|
+
let xpath = this.getXpath();
|
|
40
41
|
let checked = Boolean(await (await this.browser.findElement(xpath)).getAttribute("checked"));
|
|
41
42
|
if (checked) {
|
|
42
43
|
await (await this.browser.findElement(xpath)).click();
|
|
44
|
+
await this.browser.sleep(SwitchComponent.delayTime);
|
|
43
45
|
}
|
|
44
46
|
}
|
|
45
47
|
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 表格组件类
|
|
3
|
+
* @作者 MaoJJ
|
|
4
|
+
*/
|
|
5
|
+
class TableComponent extends require("./Component") {
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 表格组件
|
|
9
|
+
* @param {Browser} browser 浏览器
|
|
10
|
+
*/
|
|
11
|
+
constructor(browser) {
|
|
12
|
+
super(browser);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
_createRootXpath() {
|
|
16
|
+
return "";
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
_createXpath() {
|
|
20
|
+
return "//*[contains(@class,'w-table ')]";
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
_createHeaderXapth() {
|
|
24
|
+
return "//*[contains(@class,'w-table__header-wrapper')]//thead";
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
_createBodyXapth() {
|
|
28
|
+
return "//*[contains(@class,'w-table__body-wrapper')]//tbody";
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* 获取表格数据
|
|
33
|
+
* @returns 表格数据
|
|
34
|
+
*/
|
|
35
|
+
async getTableData() {
|
|
36
|
+
let ret = [];
|
|
37
|
+
let xpath = `(${this.getXpath()}${this._createBodyXapth()}//tr)[1]`;
|
|
38
|
+
await this.browser.waitUntilElementBeVisible(xpath);
|
|
39
|
+
await this.browser.sleep(TableComponent.delayTime);
|
|
40
|
+
// 处理表头
|
|
41
|
+
if (!this._createHeaderXapth()) {
|
|
42
|
+
return ret;
|
|
43
|
+
}
|
|
44
|
+
xpath = `(${this.getXpath()}${this._createHeaderXapth()}//tr)[1]/th`;
|
|
45
|
+
let titles = await this.browser.findElements(xpath);
|
|
46
|
+
for (let i = 0; i < titles.length; i++) {
|
|
47
|
+
titles[i] = ((await titles[i].getText(true)).replaceAll("\n", "")).trim();
|
|
48
|
+
}
|
|
49
|
+
// 处理表体
|
|
50
|
+
xpath = `${this.getXpath()}${this._createBodyXapth()}//tr[contains(@class, 'w-table__row')]`;
|
|
51
|
+
let trs = await this.browser.findElements(xpath);
|
|
52
|
+
for (let i = 0; i < trs.length; i++) {
|
|
53
|
+
xpath = `(${this.getXpath()}${this._createBodyXapth()}//tr[contains(@class, 'w-table__row')])[${i + 1}]/td`;
|
|
54
|
+
let tds = await this.browser.findElements(xpath);
|
|
55
|
+
let row = {};
|
|
56
|
+
for (let j = 0; j < tds.length; j++) {
|
|
57
|
+
let title = titles[j]
|
|
58
|
+
if (title) {
|
|
59
|
+
let text = (await tds[j].getText(true)).replaceAll("\n", " ");
|
|
60
|
+
row[title] = text;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
ret.push(row);
|
|
64
|
+
}
|
|
65
|
+
ret = ret.filter(row => {
|
|
66
|
+
let isDelete = true;
|
|
67
|
+
Object.keys(row).forEach(key => {
|
|
68
|
+
if (row[key] !== "") {
|
|
69
|
+
isDelete = false;
|
|
70
|
+
}
|
|
71
|
+
})
|
|
72
|
+
return !isDelete;
|
|
73
|
+
})
|
|
74
|
+
return ret;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* 获取块组件
|
|
80
|
+
* @param {Number} rowNumber 行号
|
|
81
|
+
* @param {Number} columnNumber 列号
|
|
82
|
+
* @returns 块组件
|
|
83
|
+
*/
|
|
84
|
+
blockComponent(rowNumber, columnNumber) {
|
|
85
|
+
let that = this;
|
|
86
|
+
class _BlockComponent extends require("./BlockComponent") {
|
|
87
|
+
_createRootXpath() {
|
|
88
|
+
return "";
|
|
89
|
+
}
|
|
90
|
+
_createXpath() {
|
|
91
|
+
if (columnNumber) {
|
|
92
|
+
return `${that.getXpath()}${that._createBodyXapth()}//tr[${rowNumber}]/td[${columnNumber}]`;
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
return `${that.getXpath()}${that._createBodyXapth()}//tr[${rowNumber}]`;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
return new _BlockComponent(this.browser, null);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
module.exports = TableComponent;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文本组件类
|
|
3
|
+
* @作者 MaoJJ
|
|
4
|
+
*/
|
|
5
|
+
class TextComponent 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}']`;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
module.exports = TextComponent;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 多行输入框组件类
|
|
3
|
+
* @作者 MaoJJ
|
|
4
|
+
*/
|
|
5
|
+
class TextareaComponent extends require("./Component") {
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 多行输入框组件
|
|
9
|
+
* @param {Browser} browser 浏览器
|
|
10
|
+
* @param {String} placeholder 背景文字
|
|
11
|
+
* @param {String} label 标签
|
|
12
|
+
*/
|
|
13
|
+
constructor(browser, label) {
|
|
14
|
+
super(browser);
|
|
15
|
+
this.label = label;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
_createXpath() {
|
|
19
|
+
if (this.label) {
|
|
20
|
+
return `//*[normalize-space(text())='${this.label}']/ancestor-or-self::label/..//textarea`;
|
|
21
|
+
}
|
|
22
|
+
return "//textarea"
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
module.exports = TextareaComponent;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 顶部菜单组件类
|
|
3
|
+
* @作者 MaoJJ
|
|
4
|
+
*/
|
|
5
|
+
class TopMenuComponent extends require("./Component") {
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 顶部菜单组件
|
|
9
|
+
* @param {Browser} browser 浏览器
|
|
10
|
+
*/
|
|
11
|
+
constructor(browser, firstItem) {
|
|
12
|
+
super(browser);
|
|
13
|
+
this.firstItem = firstItem;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
_createXpath() {
|
|
17
|
+
return `//*[normalize-space(text())='${this.firstItem}']/ancestor::*[contains(@class,'nav-box-item')]`;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 选择菜单
|
|
22
|
+
* @param {String} menuItem 菜单项
|
|
23
|
+
*/
|
|
24
|
+
async select(menuItem) {
|
|
25
|
+
let xpath = `${this.getXpath()}//*[normalize-space(text())='${menuItem}']/ancestor::*[contains(@class,'w-menu-item')]`;
|
|
26
|
+
await (await this.browser.findElement(xpath)).click();
|
|
27
|
+
await this.browser.sleep(TopMenuComponent.delayTime);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
module.exports = TopMenuComponent;
|