@winning-test/component 0.0.100 → 0.0.102

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.
@@ -0,0 +1,173 @@
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} xpath xpath
24
+ * @returns 块组件
25
+ */
26
+ blockComponent(xpath) {
27
+ let that = this;
28
+ class _BlockComponent extends BlockComponent {
29
+ _createRootXpath() {
30
+ return that.getXpath();
31
+ }
32
+ }
33
+ return new _BlockComponent(this.browser, xpath);
34
+ }
35
+
36
+ /**
37
+ * 获取按钮组件
38
+ * @param {String} text 文本
39
+ * @returns 按钮组件
40
+ */
41
+ buttonComponent(text) {
42
+ let that = this;
43
+ class ButtonComponent extends require("./ButtonComponent") {
44
+ _createRootXpath() {
45
+ return that.getXpath();
46
+ }
47
+ }
48
+ return new ButtonComponent(this.browser, text);
49
+ }
50
+
51
+ /**
52
+ * 获取复选框组件
53
+ * @param {String} label 标签
54
+ * @returns 复选框组件
55
+ */
56
+ checkboxComponent(label) {
57
+ let that = this;
58
+ class CheckboxComponent extends require("./CheckboxComponent") {
59
+ _createRootXpath() {
60
+ return that.getXpath();
61
+ }
62
+ }
63
+ return new CheckboxComponent(this.browser, label);
64
+ }
65
+
66
+ /**
67
+ * 获取对话框组件
68
+ * @param {String} title 标题
69
+ * @returns 对话框组件
70
+ */
71
+ dialogComponent(title) {
72
+ let that = this;
73
+ class DialogComponent extends require("./DialogComponent") {
74
+ _createRootXpath() {
75
+ return that.getXpath();
76
+ }
77
+ }
78
+ return new DialogComponent(this.browser, title);
79
+ }
80
+
81
+ /**
82
+ * 获取输入框组件
83
+ * @param {String} label 标签
84
+ * @param {String} placeholder 背景文字
85
+ * @returns 输入框组件
86
+ */
87
+ inputComponent(label, placeholder) {
88
+ let that = this;
89
+ class InputComponent extends require("./InputComponent") {
90
+ _createRootXpath() {
91
+ return that.getXpath();
92
+ }
93
+ }
94
+ return new InputComponent(this.browser, label, placeholder);
95
+ }
96
+
97
+ /**
98
+ * 获取菜单组件
99
+ * @returns 菜单组件
100
+ */
101
+ menuComponent() {
102
+ let that = this;
103
+ class MenuComponent extends require("./MenuComponent") {
104
+ _createRootXpath() {
105
+ return that.getXpath();
106
+ }
107
+ }
108
+ return new MenuComponent(this.browser);
109
+ }
110
+
111
+ /**
112
+ * 获取消息组件
113
+ * @param {Stirng} text 文本
114
+ * @returns 消息组件
115
+ */
116
+ messageComponent(text) {
117
+ let that = this;
118
+ class MessageComponent extends require("./MessageComponent") {
119
+ _createRootXpath() {
120
+ return that.getXpath();
121
+ }
122
+ }
123
+ return new MessageComponent(this.browser, text);
124
+ }
125
+
126
+ /**
127
+ * 获取选择器组件
128
+ * @param {String} label 标签
129
+ * @param {String} placeholder 背景文字
130
+ * @returns 选择器组件
131
+ */
132
+ selectComponent(label, placeholder) {
133
+ let that = this;
134
+ class SelectComponent extends require("./SelectComponent") {
135
+ _createRootXpath() {
136
+ return that.getXpath();
137
+ }
138
+ }
139
+ return new SelectComponent(this.browser, label, placeholder);
140
+ }
141
+
142
+ /**
143
+ * 获取表格组件
144
+ * @returns 表格组件
145
+ */
146
+ tableComponent() {
147
+ let that = this;
148
+ class TableComponent extends require("./TableComponent") {
149
+ _createRootXpath() {
150
+ return that.getXpath();
151
+ }
152
+ }
153
+ return new TableComponent(this.browser);
154
+ }
155
+
156
+ /**
157
+ * 获取文本组件
158
+ * @param {String} text 文本
159
+ * @returns 文本组件
160
+ */
161
+ textComponent(text) {
162
+ let that = this;
163
+ class TextComponent extends require("./TextComponent") {
164
+ _createRootXpath() {
165
+ return that.getXpath();
166
+ }
167
+ }
168
+ return new TextComponent(this.browser, text);
169
+ }
170
+
171
+ }
172
+
173
+ module.exports = BlockComponent;
@@ -0,0 +1,26 @@
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
+ if (this.text){
19
+ return `//*[normalize-space(text())='${this.text}']/ancestor-or-self::button`;
20
+ }
21
+ return "//*[@type='button']";
22
+ }
23
+
24
+ }
25
+
26
+ module.exports = ButtonComponent;
@@ -0,0 +1,46 @@
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}']/ancestor-or-self::label//input[@type='checkbox']`;
20
+ }
21
+ else {
22
+ return "//input[@type='checkbox']";
23
+ }
24
+ }
25
+
26
+ /**
27
+ * 选择
28
+ */
29
+ async select() {
30
+ if (!(await (await this.browser.findElement(this.getXpath())).isSelected())) {
31
+ await (await this.browser.findElement(this.getXpath())).click();
32
+ }
33
+ }
34
+
35
+ /**
36
+ * 取消选择
37
+ */
38
+ async unselect() {
39
+ if (await (await this.browser.findElement(this.getXpath())).isSelected()) {
40
+ await (await this.browser.findElement(this.getXpath())).click();
41
+ }
42
+ }
43
+
44
+ }
45
+
46
+ module.exports = CheckboxComponent;
@@ -0,0 +1,109 @@
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
+
52
+ async getAttribute(attributeName) {
53
+ await this.browser.sleep(Component.delayTime);
54
+ return await super.getAttribute(attributeName);
55
+ }
56
+
57
+ async waitUntilBeDisabled() {
58
+ await super.waitUntilBeDisabled();
59
+ await this.browser.sleep(Component.delayTime);
60
+ }
61
+
62
+ async waitUntilBeEnabled() {
63
+ await super.waitUntilBeEnabled();
64
+ await this.browser.sleep(Component.delayTime);
65
+ }
66
+
67
+ async waitUntilBeNotVisible() {
68
+ await super.waitUntilBeNotVisible();
69
+ await this.browser.sleep(Component.delayTime);
70
+ }
71
+
72
+ async waitUntilBeVisible() {
73
+ await super.waitUntilBeVisible();
74
+ await this.browser.sleep(Component.delayTime);
75
+ }
76
+
77
+ async isEnabled() {
78
+ return await super.isEnabled();
79
+ }
80
+
81
+ /**
82
+ * 鼠标移动到组件后悬停
83
+ */
84
+ async moveMouseTo() {
85
+ await this.browser.moveMouseTo(this.getXpath());
86
+ await this.browser.sleep(Component.delayTime);
87
+ }
88
+
89
+ /**
90
+ * 滚动页面到元素位置
91
+ */
92
+ async scrollIntoView() {
93
+ (await this.browser.findElement(this.getXpath())).scrollIntoView();
94
+ }
95
+
96
+ /**
97
+ * 右击
98
+ */
99
+ async contextClick() {
100
+ const { By, until } = require("selenium-webdriver");
101
+ const xpath = this.getXpath();
102
+ await this.browser.webDriver.wait(until.elementLocated(By.xpath(xpath)), this.browser.config.timeout);
103
+ let actions = this.browser.webDriver.actions();
104
+ actions.contextClick(await this.browser.webDriver.findElement(By.xpath(xpath)))
105
+ await actions.perform();
106
+ }
107
+ }
108
+
109
+ module.exports = Component;
@@ -0,0 +1,26 @@
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, null, null);
14
+ this.title = title;
15
+ }
16
+
17
+ _createXpath() {
18
+ if (this.title){
19
+ return `//*[contains(normalize-space(text()),'${this.title}')]/ancestor::*[contains(@class,'el-dialog')]`;
20
+ }
21
+ return `//*[contains(@class,'el-dialog')]`;
22
+ }
23
+
24
+ }
25
+
26
+ 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} label 标签
11
+ * @param {String} placeholder 背景文字
12
+ */
13
+ constructor(browser, label, placeholder) {
14
+ super(browser);
15
+ this.label = label;
16
+ this.placeholder = placeholder;
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}']/../..//input`;
25
+ }
26
+ return "//input[@type='text']";
27
+ }
28
+
29
+ }
30
+
31
+ module.exports = InputComponent;
@@ -0,0 +1,36 @@
1
+ /**
2
+ * 菜单组件类
3
+ * @作者 MaoJJ
4
+ */
5
+ class MenuComponent extends require("./Component") {
6
+
7
+ /**
8
+ * 菜单组件
9
+ * @param {Browser} browser 浏览器
10
+ */
11
+ constructor(browser) {
12
+ super(browser);
13
+ }
14
+
15
+ _createXpath() {
16
+ return "//*[contains(@class,'menuListBtn')]";
17
+ }
18
+
19
+ /**
20
+ * 选择菜单
21
+ * @param {String} firstMenuItem 一级菜单
22
+ * @param {String} secondMenuItem 二级菜单
23
+ */
24
+ async select(firstMenuItem, secondMenuItem) {
25
+ await this.browser.switchToFrame();
26
+ let xpath = this.getXpath();
27
+ await (await this.browser.findElement(xpath)).click();
28
+ xpath = `//*[contains(@class,'menuListBox')]//*[text()='${firstMenuItem}']/..//*[text()='${secondMenuItem}']`;
29
+ await (await this.browser.findElement(xpath)).click();
30
+ xpath = "//iframe[not (@style='display: none;')]";
31
+ await this.browser.switchToFrame(xpath)
32
+ }
33
+
34
+ }
35
+
36
+ module.exports = MenuComponent;
@@ -0,0 +1,87 @@
1
+ /**
2
+ * 消息组件类
3
+ * @作者: MaoJJ
4
+ */
5
+ class MessageComponent extends require("./Component") {
6
+
7
+ /**
8
+ * 消息组件
9
+ * @param {Browser} browser 浏览器
10
+ * @param {String} text 消息内容
11
+ * @param {Boolean} iframe 是否在iframe内
12
+ */
13
+ constructor(browser, text, iframe = false) {
14
+ super(browser)
15
+ this.text = text;
16
+ this.iframe = iframe;
17
+ }
18
+
19
+ _createXpath() {
20
+ return `//*[contains(normalize-space(text()),'${this.text}')]/ancestor-or-self::*[contains(@class,'el-message')]`;
21
+ }
22
+
23
+ /**
24
+ * 获取消息内容
25
+ * @returns 消息内容
26
+ */
27
+ async getText() {
28
+ if (!this.iframe) {
29
+ await this.browser.switchToFrame();
30
+ }
31
+ let xpath = this.getXpath();
32
+ let text = await (await this.browser.findElement(xpath)).getText();
33
+ if (!this.iframe) {
34
+ xpath = "//iframe[not (@style='display: none;')]";
35
+ await this.browser.switchToFrame(xpath)
36
+ }
37
+ return text;
38
+ }
39
+
40
+ /**
41
+ * 等待出现
42
+ */
43
+ async waitUntilBeVisible() {
44
+ if (!this.iframe) {
45
+ await this.browser.switchToFrame();
46
+ }
47
+ let xpath = this.getXpath();
48
+ await this.browser.waitUntilElementBeVisible(xpath);
49
+ if (!this.iframe) {
50
+ xpath = "//iframe[not (@style='display: none;')]";
51
+ await this.browser.switchToFrame(xpath);
52
+ }
53
+ }
54
+
55
+ /**
56
+ * 等待消失
57
+ */
58
+ async waitUntilBeNotVisible() {
59
+ if (!this.iframe) {
60
+ await this.browser.switchToFrame();
61
+ }
62
+ let xpath = this.getXpath();
63
+ await this.browser.waitUntilElementBeNotVisible(xpath);
64
+ if (!this.iframe) {
65
+ xpath = "//iframe[not (@style='display: none;')]";
66
+ await this.browser.switchToFrame(xpath);
67
+ }
68
+ }
69
+
70
+ /**
71
+ * 关闭
72
+ */
73
+ async close() {
74
+ if (!this.iframe) {
75
+ await this.browser.switchToFrame();
76
+ }
77
+ let xpath = `${this.getXpath()}//i[contains(@class,'el-message__closeBtn')]`;
78
+ await (await this.browser.findElement(xpath)).click();
79
+ if (!this.iframe) {
80
+ xpath = "//iframe[not (@style='display: none;')]";
81
+ await this.browser.switchToFrame(xpath);
82
+ }
83
+ }
84
+
85
+ }
86
+
87
+ module.exports = MessageComponent;
@@ -0,0 +1,41 @@
1
+ /**
2
+ * 单选框组件类
3
+ * @作者 MaoJJ
4
+ */
5
+ class RadioComponent 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
+ return `//*[normalize-space(text())='${this.label}']/ancestor-or-self::label//input[@type='radio']`;
19
+ }
20
+
21
+ /**
22
+ * 选择
23
+ */
24
+ async select() {
25
+ if (!(await (await this.browser.findElement(this.getXpath())).isSelected())) {
26
+ await (await this.browser.findElement(this.getXpath())).click();
27
+ }
28
+ }
29
+
30
+ /**
31
+ * 取消选择
32
+ */
33
+ async unselect() {
34
+ if (await (await this.browser.findElement(this.getXpath())).isSelected()) {
35
+ await (await this.browser.findElement(this.getXpath())).click();
36
+ }
37
+ }
38
+
39
+ }
40
+
41
+ module.exports = RadioComponent;
@@ -0,0 +1,43 @@
1
+ /**
2
+ * 选择器组件类
3
+ * @作者 MaoJJ
4
+ */
5
+ class SelectComponent extends require("./Component") {
6
+
7
+ /**
8
+ * 选择器组件
9
+ * @param {Browser} browser 浏览器
10
+ * @param {String} label 标签
11
+ * @param {String} placeholder 背景文字
12
+ */
13
+ constructor(browser, label,placeholder) {
14
+ super(browser);
15
+ this.label = label;
16
+ this.placeholder = placeholder;
17
+ }
18
+
19
+ _createXpath() {
20
+ if (this.label) {
21
+ return `//*[normalize-space(text())='${this.label}']/../..//input`;
22
+ }
23
+ if (this.placeholder) {
24
+ return `//input[@placeholder='${this.placeholder}']`;
25
+ }
26
+ return "//input[@type='text']";
27
+ }
28
+
29
+ async select(...items) {
30
+ let xpath = this.getXpath();
31
+ await (await this.browser.findElement(xpath)).click();
32
+ xpath = "//*[@class='el-autocomplete-suggestion' and not (contains(@style,'display: none'))]";
33
+ await this.browser.waitUntilElementBeVisible(xpath);
34
+ for (let i = 0; i < items.length; i++) {
35
+ let item = items[i];
36
+ xpath = `//*[@class='el-autocomplete-suggestion' and not (contains(@style,'display: none'))]//*[contains(text(),'${item}')]/ancestor::li`;
37
+ await (await this.browser.findElement(xpath)).click();
38
+ }
39
+ }
40
+
41
+ }
42
+
43
+ module.exports = SelectComponent;
@@ -0,0 +1,113 @@
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,'vxe-table ')]";
21
+ }
22
+
23
+ _createHeaderXapth() {
24
+ return "//thead";
25
+ }
26
+
27
+ _createBodyXapth() {
28
+ return "//tbody";
29
+ }
30
+
31
+ /**
32
+ * 获取表格数据
33
+ * @returns 表格数据
34
+ */
35
+ async getTableData() {
36
+ let ret = [];
37
+ let xpath = `(${this.getXpath()}${this._createBodyXapth()}//tr)[1]`;
38
+ if (!(await this.browser.isDisplayed(xpath, this.browser.config.timeout))) {
39
+ return ret;
40
+ }
41
+ await this.browser.sleep(TableComponent.delayTime);
42
+ // 处理表头
43
+ if (!this._createHeaderXapth()) {
44
+ return ret;
45
+ }
46
+ xpath = `(${this.getXpath()}${this._createHeaderXapth()}//tr)[1]/th`;
47
+ let titles = await this.browser.findElements(xpath);
48
+ for (let i = 0; i < titles.length; i++) {
49
+ titles[i] = (await titles[i].getText(true)).trim() || `#${String(i).padStart(3, "0")}`;
50
+ }
51
+ // 处理表体
52
+ xpath = `(${this.getXpath()}${this._createBodyXapth()})[1]//tr`;
53
+ let trs = await this.browser.findElements(xpath);
54
+ for (let i = 0; i < trs.length; i++) {
55
+ xpath = `(${this.getXpath()}${this._createBodyXapth()}//tr)[${i + 1}]/td`;
56
+ let tds = await this.browser.findElements(xpath);
57
+ let row = {};
58
+ for (let j = 0; j < tds.length; j++) {
59
+ let title = titles[j]
60
+ let text = (await tds[j].getText(true)).replaceAll("\n", " ");
61
+ row[title] = text;
62
+ }
63
+ ret.push(row);
64
+ }
65
+ return ret;
66
+ }
67
+
68
+ /**
69
+ * 根据列名获取列号
70
+ * @param {Str} columnStr 列名
71
+ * @returns {Number} columnNumber 列号
72
+ */
73
+ async getColumnNumberByTitle(columnStr) {
74
+ let xpath = `(${this.getXpath()}${this._createBodyXapth()}//tr)[1]`;
75
+ if (!(await this.browser.isDisplayed(xpath, this.browser.config.timeout))) {
76
+ return;
77
+ }
78
+ await this.browser.sleep(TableComponent.delayTime);
79
+ xpath = `(${this.getXpath()}${this._createHeaderXapth()}//tr)[1]/th`;
80
+ let titles = await this.browser.findElements(xpath);
81
+ for (let i = 0; i < titles.length; i++) {
82
+ titles[i] = (await titles[i].getText(true)).trim() || `#${String(i).padStart(3, "0")}`;
83
+ }
84
+ let columnNumber = titles.indexOf(columnStr) + 1;
85
+ return columnNumber
86
+ }
87
+
88
+ /**
89
+ * 获取块组件
90
+ * @param {Number} rowNumber 行号
91
+ * @param {Number} columnNumber 列号
92
+ * @returns 块组件
93
+ */
94
+ blockComponent(rowNumber, columnNumber) {
95
+ let that = this;
96
+ class _BlockComponent extends require("./BlockComponent") {
97
+ _createRootXpath() {
98
+ return "";
99
+ }
100
+ _createXpath() {
101
+ if (columnNumber) {
102
+ return `${that.getXpath()}${that._createBodyXapth()}//tr[${rowNumber}]/td[${columnNumber}]`;
103
+ }
104
+ else {
105
+ return `${that.getXpath()}${that._createBodyXapth()}//tr[${rowNumber}]`;
106
+ }
107
+ }
108
+ }
109
+ return new _BlockComponent(this.browser, null);
110
+ }
111
+ }
112
+
113
+ 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,172 @@
1
+ const BlockComponent = require("../component/BlockComponent");
2
+ const ButtonComponent = require("../component/ButtonComponent");
3
+ const CheckboxComponent = require("../component/CheckboxComponent");
4
+ const DialogComponent = require("../component/DialogComponent");
5
+ const InputComponent = require("../component/InputComponent");
6
+ const MenuComponent = require("../component/MenuComponent");
7
+ const MessageComponent = require("../component/MessageComponent");
8
+ const RadioComponent = require("../component/RadioComponent");
9
+ const SelectComponent = require("../component/SelectComponent");
10
+ const TableComponent = require("../component/TableComponent");
11
+ const TextComponent = require("../component/TextComponent");
12
+
13
+ /**
14
+ * 页面类
15
+ */
16
+ class Page extends require("@winning-test/autotest-webui").Page {
17
+
18
+ /**
19
+ * 页面类
20
+ * @param {Browser} browser 浏览器
21
+ */
22
+ constructor(browser) {
23
+ super(browser);
24
+ }
25
+
26
+ /**
27
+ * 获取块组件
28
+ * @param {String} xpath xpath
29
+ * @returns 块组件
30
+ */
31
+ blockComponent(xpath) {
32
+ return new BlockComponent(this.browser, xpath);
33
+ }
34
+
35
+ /**
36
+ * 获取按钮组件
37
+ * @param {String} text 文本
38
+ * @returns 按钮组件
39
+ */
40
+ buttonComponent(text) {
41
+ return new ButtonComponent(this.browser, text);
42
+ }
43
+
44
+ /**
45
+ * 获取复选框组件
46
+ * @param {String} label 标签
47
+ * @returns 复选框组件
48
+ */
49
+ checkboxComponent(label) {
50
+ return new CheckboxComponent(this.browser, label);
51
+ }
52
+
53
+ /**
54
+ * 获取对话框组件
55
+ * @param {String} title 标题
56
+ * @returns 对话框组件
57
+ */
58
+ dialogComponent(title) {
59
+ return new DialogComponent(this.browser, title);
60
+ }
61
+
62
+ /**
63
+ * 获取输入框组件
64
+ * @param {String} label 标签
65
+ * @param {String} placeholder 背景文字
66
+ * @returns 输入框组件
67
+ */
68
+ inputComponent(label, placeholder) {
69
+ return new InputComponent(this.browser, label, placeholder);
70
+ }
71
+
72
+
73
+ /**
74
+ * 获取菜单组件
75
+ * @returns 菜单组件
76
+ */
77
+ menuComponent() {
78
+ return new MenuComponent(this.browser);
79
+ }
80
+
81
+ /**
82
+ * 获取消息组件
83
+ * @param {Stirng} text 文本
84
+ * @param {Boolean} iframe 是否在iframe内
85
+ * @returns 消息组件
86
+ */
87
+ messageComponent(text, iframe = false) {
88
+ return new MessageComponent(this.browser, text, iframe);
89
+ }
90
+
91
+ /**
92
+ * 获取选择器组件
93
+ * @param {String} label 标签
94
+ * @param {String} placeholder 背景文字
95
+ * @returns 选择器组件
96
+ */
97
+ selectComponent(label, placeholder) {
98
+ return new SelectComponent(this.browser, label, placeholder);
99
+ }
100
+
101
+ /**
102
+ * 获取表格组件
103
+ * @returns 表格组件
104
+ */
105
+ tableComponent() {
106
+ return new TableComponent(this.browser);
107
+ }
108
+
109
+ /**
110
+ * 获取文本组件
111
+ * @param {String} text 文本
112
+ * @returns 文本组件
113
+ */
114
+ textComponent(text) {
115
+ return new TextComponent(this.browser, text);
116
+ }
117
+
118
+ /**
119
+ * 获取单选框组件
120
+ * @param {String} label 标签
121
+ * @returns 单选框组件
122
+ */
123
+ radioComponent(label) {
124
+ return new RadioComponent(this.browser, label)
125
+ }
126
+
127
+ /**
128
+ * 等待加载
129
+ */
130
+ async loading() {
131
+ try {
132
+ let xpath = "//*[contains(text(),'加载中') or contains(@class,'el-loading-mask')][not (ancestor-or-self::*[contains(@style,'display: none')])]";
133
+ if (await this.browser.isDisplayed(xpath, 1000)) {
134
+ await this.browser.waitUntilElementBeNotVisible(xpath);
135
+ }
136
+ } catch (error) {
137
+
138
+ }
139
+ }
140
+
141
+ /**
142
+ * 切换到活动Frame
143
+ */
144
+ async switchToActiveFrame() {
145
+ await this.browser.switchToFrame();
146
+ let xpath = "//iframe[not (@style='display: none;')]";
147
+ await this.browser.switchToFrame(xpath)
148
+ }
149
+
150
+ /**
151
+ * 切换到最外层iframe
152
+ */
153
+ async switchToDefultFrame() {
154
+ await this.browser.switchToFrame();
155
+ }
156
+
157
+ /**
158
+ * 切换到对应的iframe
159
+ * @param {string} id
160
+ */
161
+ async switchToFrame(id) {
162
+ try {
163
+ await this.browser.switchToFrame(`//iframe[@id='${id}']`);
164
+
165
+ } catch (error) {
166
+
167
+ }
168
+ }
169
+
170
+ }
171
+
172
+ module.exports = Page;
@@ -35,7 +35,18 @@ class SelectComponent extends require("./Component") {
35
35
  while (count > 0) {
36
36
  try {
37
37
  await this._select(...items);
38
- const value = await this.getValue();
38
+ let value = await this.getValue();
39
+ if (!(value)) {
40
+ let strlist = [];
41
+ let strsum = "";
42
+ let xpath = `${this.getXpath()}/parent::div`;
43
+ let divlist = await this.browser.findElements(xpath);
44
+ for (let index = 0; index < divlist.length; index++) {
45
+ strlist[index] = (await divlist[index].getText(true)).trim();
46
+ }
47
+ strlist.forEach((str) => { strsum += str; });
48
+ value = strsum;
49
+ }
39
50
  if (!(value && items.join().indexOf(value) !== -1)) {
40
51
  throw new Error(`选择${items}失败`);
41
52
  }
@@ -65,6 +65,26 @@ class TableComponent extends require("./Component") {
65
65
  return ret;
66
66
  }
67
67
 
68
+ /**
69
+ * 根据列名获取列号
70
+ * @param {columnStr} columnStr 列名
71
+ * @returns 列号
72
+ */
73
+ async getColumnNumberByTitle(columnStr) {
74
+ let xpath = `(${this.getXpath()}${this._createBodyXapth()}//tr)[1]`;
75
+ if (!(await this.browser.isDisplayed(xpath, this.browser.config.timeout))) {
76
+ return;
77
+ }
78
+ await this.browser.sleep(TableComponent.delayTime);
79
+ xpath = `(${this.getXpath()}${this._createHeaderXapth()}//tr)[1]/th`;
80
+ let titles = await this.browser.findElements(xpath);
81
+ for (let i = 0; i < titles.length; i++) {
82
+ titles[i] = (await titles[i].getText(true)).trim() || `#${String(i).padStart(3, "0")}`;
83
+ }
84
+ let columnNumber = titles.indexOf(columnStr) + 1;
85
+ return columnNumber
86
+ }
87
+
68
88
 
69
89
  /**
70
90
  * 获取块组件
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@winning-test/component",
3
- "version": "0.0.100",
3
+ "version": "0.0.102",
4
4
  "description": "",
5
5
  "main": "",
6
6
  "scripts": {
@@ -157,7 +157,7 @@ class Page extends require("@winning-test/autotest-webui").Page {
157
157
  */
158
158
  async loading() {
159
159
  try {
160
- const xpath = "//*[contains(text(),'加载中') or @class='el-loading-mask'][not (ancestor-or-self::*[contains(@style,'display: none')])]";
160
+ const xpath = "//*[contains(text(),'加载中') or @class='el-loading-mask' or @class='el-icon-loading'][not (ancestor-or-self::*[contains(@style,'display: none')])]";
161
161
  if (await this.browser.isDisplayed(xpath, 1000)) {
162
162
  await this.browser.waitUntilElementBeNotVisible(xpath);
163
163
  }