@winning-test/component 0.0.77 → 0.0.78

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,233 @@
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} placeholder 背景文字
54
+ * @param {String} label 标签
55
+ * @returns 级联选择器组件
56
+ */
57
+ cascaderComponent(placeholder, label) {
58
+ let that = this;
59
+ class CascaderComponent extends require("./CascaderComponent") {
60
+ _createRootXpath() {
61
+ return that.getXpath();
62
+ }
63
+ }
64
+ return new CascaderComponent(this.browser, placeholder, label);
65
+ }
66
+
67
+ /**
68
+ * 获取复选框组件
69
+ * @param {String} label 标签
70
+ * @returns 复选框组件
71
+ */
72
+ checkboxComponent(label) {
73
+ let that = this;
74
+ class CheckboxComponent extends require("./CheckboxComponent") {
75
+ _createRootXpath() {
76
+ return that.getXpath();
77
+ }
78
+ }
79
+ return new CheckboxComponent(this.browser, label);
80
+ }
81
+
82
+ /**
83
+ * 获取对话框组件
84
+ * @param {String} title 标题
85
+ * @returns 对话框组件
86
+ */
87
+ dialogComponent(title) {
88
+ let that = this;
89
+ class DialogComponent extends require("./DialogComponent") {
90
+ _createRootXpath() {
91
+ return that.getXpath();
92
+ }
93
+ }
94
+ return new DialogComponent(this.browser, title);
95
+ }
96
+
97
+ /**
98
+ * 获取输入框组件
99
+ * @param {String} label 标签
100
+ * @param {String} placeholder 背景文字
101
+ * @returns 输入框组件
102
+ */
103
+ inputComponent(label, placeholder) {
104
+ let that = this;
105
+ class InputComponent extends require("./InputComponent") {
106
+ _createRootXpath() {
107
+ return that.getXpath();
108
+ }
109
+ }
110
+ return new InputComponent(this.browser, label, placeholder);
111
+ }
112
+
113
+ /**
114
+ * 获取左侧菜单组件
115
+ * @returns 左侧菜单组件
116
+ */
117
+ leftMenuComponent() {
118
+ let that = this;
119
+ class LeftMenuComponent extends require("./MenuComponent") {
120
+ _createRootXpath() {
121
+ return that.getXpath();
122
+ }
123
+ }
124
+ return new LeftMenuComponent(this.browser);
125
+ }
126
+
127
+ /**
128
+ * 获取列表组件
129
+ * @returns 列表组件
130
+ */
131
+ listComponent() {
132
+ let that = this;
133
+ class ListComponent extends require("./ListComponent") {
134
+ _createRootXpath() {
135
+ return that.getXpath();
136
+ }
137
+ }
138
+ return new ListComponent(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} label 标签
174
+ * @param {String} placeholder 背景文字
175
+ * @returns 选择器组件
176
+ */
177
+ selectComponent(label, placeholder) {
178
+ let that = this;
179
+ class SelectComponent extends require("./SelectComponent") {
180
+ _createRootXpath() {
181
+ return that.getXpath();
182
+ }
183
+ }
184
+ return new SelectComponent(this.browser, label, placeholder);
185
+ }
186
+
187
+ /**
188
+ * 获取开关组件
189
+ * @param {String} label 标签
190
+ * @returns 开关组件
191
+ */
192
+ switchComponent(label) {
193
+ let that = this;
194
+ class SwitchComponent extends require("./SwitchComponent") {
195
+ _createRootXpath() {
196
+ return that.getXpath();
197
+ }
198
+ }
199
+ return new SwitchComponent(this.browser, label);
200
+ }
201
+
202
+ /**
203
+ * 获取表格组件
204
+ * @returns 表格组件
205
+ */
206
+ tableComponent() {
207
+ let that = this;
208
+ class TableComponent extends require("./TableComponent") {
209
+ _createRootXpath() {
210
+ return that.getXpath();
211
+ }
212
+ }
213
+ return new TableComponent(this.browser);
214
+ }
215
+
216
+ /**
217
+ * 获取文本组件
218
+ * @param {String} text 文本
219
+ * @returns 文本组件
220
+ */
221
+ textComponent(text) {
222
+ let that = this;
223
+ class TextComponent extends require("./TextComponent") {
224
+ _createRootXpath() {
225
+ return that.getXpath();
226
+ }
227
+ }
228
+ return new TextComponent(this.browser, text);
229
+ }
230
+
231
+ }
232
+
233
+ 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}' or @value='${this.text}']`;
20
+ }
21
+ return "//*[@type='button']";
22
+ }
23
+
24
+ }
25
+
26
+ module.exports = ButtonComponent;
@@ -0,0 +1,51 @@
1
+ /**
2
+ * 级联选择器组件类
3
+ * @作者 MaoJJ
4
+ */
5
+ class CascaderComponent 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}']/..//input`;
25
+ }
26
+ }
27
+
28
+ /**
29
+ * 选择
30
+ * @param {...String} items 选项
31
+ */
32
+ async select(...items) {
33
+ class ListComponent extends require("./ListComponent") {
34
+ _createXpath() {
35
+ return "//*[contains(@class,'el-scrollbar')]//ul"
36
+ }
37
+ }
38
+ let xpath = this.getXpath();
39
+ await (await this.browser.findElement(xpath)).click();
40
+ let listComponent = new ListComponent(this.browser);
41
+ await listComponent.waitUntilBeVisible();
42
+ for (let i = 0; i < items.length; i++) {
43
+ let item = items[i];
44
+ let listComponent = new ListComponent(this.browser);
45
+ await listComponent.select(item);
46
+ }
47
+ }
48
+
49
+ }
50
+
51
+ module.exports = CascaderComponent;
@@ -0,0 +1,56 @@
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}']/../..//*[@class='el-checkbox']`;
20
+ }
21
+ return "//*[@class='el-checkbox']";
22
+ }
23
+
24
+ /**
25
+ * 选择选项
26
+ * @param {...String} items 选项
27
+ */
28
+ async select(...items) {
29
+ let xpath = null;
30
+ for (let i = 0; i < items.length; i++) {
31
+ let item = items[i];
32
+ xpath = `${this.getXpath()}//*[text()='${item}']/..//input`;
33
+ if (!(await (await this.browser.findElement(xpath)).isSelected())) {
34
+ await (await this.browser.findElement(xpath)).click();
35
+ }
36
+ }
37
+ }
38
+
39
+ /**
40
+ * 取消选择选项
41
+ * @param {...String} items 选项
42
+ */
43
+ async unselect(...items) {
44
+ let xpath = null;
45
+ for (let i = 0; i < items.length; i++) {
46
+ let item = items[i];
47
+ xpath = `${this.getXpath()}//*[text()='${item}']/..//input`;
48
+ if (await (await this.browser.findElement(xpath)).isSelected()) {
49
+ await (await this.browser.findElement(xpath)).click();
50
+ }
51
+ }
52
+ }
53
+
54
+ }
55
+
56
+ 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,57 @@
1
+ /**
2
+ * 消息组件类
3
+ * @作者: MaoJJ
4
+ */
5
+ class MessageComponent 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(normalize-space(text()),'${this.text}')]/ancestor-or-self::*[@role='alert']`;
19
+ }
20
+
21
+ /**
22
+ * 获取消息内容
23
+ * @returns 消息内容
24
+ */
25
+ async getText() {
26
+ let xpath = this.getXpath();
27
+ let text = await (await this.browser.findElement(xpath)).getText();
28
+ return text;
29
+ }
30
+
31
+ /**
32
+ * 等待出现
33
+ */
34
+ async waitUntilBeVisible() {
35
+ let xpath = this.getXpath();
36
+ await this.browser.waitUntilElementBeVisible(xpath);
37
+ }
38
+
39
+ /**
40
+ * 等待消失
41
+ */
42
+ async waitUntilBeNotVisible() {
43
+ let xpath = this.getXpath();
44
+ await this.browser.waitUntilElementBeNotVisible(xpath);
45
+ }
46
+
47
+ /**
48
+ * 关闭
49
+ */
50
+ async close() {
51
+ let xpath = `${this.getXpath()}//i[contains(@class,'el-message__closeBtn')]`;
52
+ await (await this.browser.findElement(xpath)).click();
53
+ }
54
+
55
+ }
56
+
57
+ 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,48 @@
1
+ /**
2
+ * 开关组件类
3
+ * @作者 MaoJJ
4
+ */
5
+ class SwitchComponent 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}']/..//*[@role='switch']`;
20
+ }
21
+ return "//*[@role='switch']";
22
+ }
23
+
24
+ /**
25
+ * 打开
26
+ */
27
+ async on() {
28
+ let xpath = `${this.getXpath()}//input[@type='checkbox']`;
29
+ let checked = Boolean(await (await this.browser.findElement(xpath)).getAttribute("checked"));
30
+ if (!checked) {
31
+ await (await this.browser.findElement(xpath)).click();
32
+ }
33
+ }
34
+
35
+ /**
36
+ * 关闭
37
+ */
38
+ async off() {
39
+ let xpath = `${this.getXpath()}//input[@type='checkbox']`;
40
+ let checked = Boolean(await (await this.browser.findElement(xpath)).getAttribute("checked"));
41
+ if (checked) {
42
+ await (await this.browser.findElement(xpath)).click();
43
+ }
44
+ }
45
+
46
+ }
47
+
48
+ module.exports = SwitchComponent;
@@ -0,0 +1,94 @@
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
+ * 获取块组件
71
+ * @param {Number} rowNumber 行号
72
+ * @param {Number} columnNumber 列号
73
+ * @returns 块组件
74
+ */
75
+ blockComponent(rowNumber, columnNumber) {
76
+ let that = this;
77
+ class _BlockComponent extends require("./BlockComponent") {
78
+ _createRootXpath() {
79
+ return "";
80
+ }
81
+ _createXpath() {
82
+ if (columnNumber) {
83
+ return `${that.getXpath()}${that._createBodyXapth()}//tr[${rowNumber}]/td[${columnNumber}]`;
84
+ }
85
+ else {
86
+ return `${that.getXpath()}${that._createBodyXapth()}//tr[${rowNumber}]`;
87
+ }
88
+ }
89
+ }
90
+ return new _BlockComponent(this.browser, null);
91
+ }
92
+ }
93
+
94
+ 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,180 @@
1
+ const BlockComponent = require("../component/BlockComponent");
2
+ const ButtonComponent = require("../component/ButtonComponent");
3
+ const CascaderComponent = require("../component/CascaderComponent");
4
+ const CheckboxComponent = require("../component/CheckboxComponent");
5
+ const DialogComponent = require("../component/DialogComponent");
6
+ const InputComponent = require("../component/InputComponent");
7
+ const ListComponent = require("../component/ListComponent");
8
+ const MenuComponent = require("../component/MenuComponent");
9
+ const MessageComponent = require("../component/MessageComponent");
10
+ const RadioComponent = require("../component/RadioComponent");
11
+ const SelectComponent = require("../component/SelectComponent");
12
+ const SwitchComponent = require("../component/SwitchComponent");
13
+ const TableComponent = require("../component/TableComponent");
14
+ const TextComponent = require("../component/TextComponent");
15
+
16
+ /**
17
+ * 页面类
18
+ */
19
+ class Page extends require("@winning-test/autotest-webui").Page {
20
+
21
+ /**
22
+ * 页面类
23
+ * @param {Browser} browser 浏览器
24
+ */
25
+ constructor(browser) {
26
+ super(browser);
27
+ }
28
+
29
+ /**
30
+ * 获取块组件
31
+ * @param {String} xpath xpath
32
+ * @returns 块组件
33
+ */
34
+ blockComponent(xpath) {
35
+ return new BlockComponent(this.browser, xpath);
36
+ }
37
+
38
+ /**
39
+ * 获取按钮组件
40
+ * @param {String} text 文本
41
+ * @returns 按钮组件
42
+ */
43
+ buttonComponent(text) {
44
+ return new ButtonComponent(this.browser, text);
45
+ }
46
+
47
+ /**
48
+ * 获取级联选择器组件
49
+ * @param {String} placeholder 背景文字
50
+ * @param {String} label 标签
51
+ * @returns 级联选择器组件
52
+ */
53
+ cascaderComponent(placeholder, label) {
54
+ return new CascaderComponent(this.browser, placeholder, label);
55
+ }
56
+
57
+ /**
58
+ * 获取复选框组件
59
+ * @param {String} label 标签
60
+ * @returns 复选框组件
61
+ */
62
+ checkboxComponent(label) {
63
+ return new CheckboxComponent(this.browser, label);
64
+ }
65
+
66
+ /**
67
+ * 获取对话框组件
68
+ * @param {String} title 标题
69
+ * @returns 对话框组件
70
+ */
71
+ dialogComponent(title) {
72
+ return new DialogComponent(this.browser, title);
73
+ }
74
+
75
+ /**
76
+ * 获取输入框组件
77
+ * @param {String} label 标签
78
+ * @param {String} placeholder 背景文字
79
+ * @returns 输入框组件
80
+ */
81
+ inputComponent(label, placeholder) {
82
+ return new InputComponent(this.browser, label, placeholder);
83
+ }
84
+
85
+ /**
86
+ * 获取列表组件
87
+ * @returns 列表组件
88
+ */
89
+ listComponent() {
90
+ return new ListComponent(this.browser);
91
+ }
92
+
93
+ /**
94
+ * 获取菜单组件
95
+ * @returns 左侧菜单组件
96
+ */
97
+ menuComponent() {
98
+ return new MenuComponent(this.browser);
99
+ }
100
+
101
+ /**
102
+ * 获取消息组件
103
+ * @param {Stirng} text 文本
104
+ * @returns 消息组件
105
+ */
106
+ messageComponent(text) {
107
+ return new MessageComponent(this.browser, text);
108
+ }
109
+
110
+ /**
111
+ * 获取选择器组件
112
+ * @param {String} label 标签
113
+ * @param {String} placeholder 背景文字
114
+ * @returns 选择器组件
115
+ */
116
+ selectComponent(label, placeholder) {
117
+ return new SelectComponent(this.browser, label, placeholder);
118
+ }
119
+
120
+ /**
121
+ * 获取开关组件
122
+ * @param {String} label 标签
123
+ * @returns 开关组件
124
+ */
125
+ switchComponent(label) {
126
+ return new SwitchComponent(this.browser, label);
127
+ }
128
+
129
+ /**
130
+ * 获取表格组件
131
+ * @returns 表格组件
132
+ */
133
+ tableComponent() {
134
+ return new TableComponent(this.browser);
135
+ }
136
+
137
+ /**
138
+ * 获取文本组件
139
+ * @param {String} text 文本
140
+ * @returns 文本组件
141
+ */
142
+ textComponent(text) {
143
+ return new TextComponent(this.browser, text);
144
+ }
145
+
146
+ /**
147
+ * 获取单选框组件
148
+ * @param {String} label 标签
149
+ * @returns 单选框组件
150
+ */
151
+ radioComponent(label) {
152
+ return new RadioComponent(this.browser, label)
153
+ }
154
+
155
+ /**
156
+ * 等待加载
157
+ */
158
+ async loading() {
159
+ try {
160
+ let xpath = "//*[contains(text(),'加载中') or contains(@class,'el-loading-mask')][not (ancestor-or-self::*[contains(@style,'display: none')])]";
161
+ if (await this.browser.isDisplayed(xpath, 1000)) {
162
+ await this.browser.waitUntilElementBeNotVisible(xpath);
163
+ }
164
+ } catch (error) {
165
+
166
+ }
167
+ }
168
+
169
+ /**
170
+ * 切换到活动Frame
171
+ */
172
+ async switchToActiveFrame() {
173
+ await this.browser.switchToFrame();
174
+ let xpath = "//iframe[not (@style='display: none;')]";
175
+ await this.browser.switchToFrame(xpath)
176
+ }
177
+
178
+ }
179
+
180
+ module.exports = Page;
@@ -0,0 +1,69 @@
1
+ const { Browser, Key } = require("@winning-test/autotest-webui");
2
+ const config = require("./component.test.json");
3
+ const Page = require("../page/Page")
4
+ const browser = new Browser();
5
+
6
+ beforeAll(async () => {
7
+ await browser.maximize();
8
+ await browser.get(config.url);
9
+ })
10
+
11
+ test.skip("001", async () => {
12
+ const page = new Page(browser);
13
+ await page.inputComponent(null, "请输入登录账户").input("yj");
14
+ await page.inputComponent(null, "请输入登录密码").input("1");
15
+ await page.buttonComponent().click();
16
+ await page.menuComponent().select("标本采集","门诊采集");
17
+ await page.menuComponent().select("标本采集","标本查询");
18
+ await page.inputComponent("扫描条码").input("1111",Key.ENTER);
19
+ await page.inputComponent("发票号").input("22222");
20
+ await page.checkboxComponent("病人类型").select("门诊","体检","其他");
21
+ await page.checkboxComponent("病人类型").unselect("住院");
22
+ await page.selectComponent("标本状态").select("已绑定");
23
+ })
24
+
25
+ test.skip("002", async () => {
26
+ const page = new Page(browser);
27
+ await page.inputComponent(null, "请输入登录账户").input("yj");
28
+ await page.inputComponent(null, "请输入登录密码").input("1");
29
+ await page.buttonComponent().click();
30
+ await page.menuComponent().select("标本采集","门诊采集");
31
+ await page.inputComponent(null,"读卡用F8或←").input("000002319",Key.ENTER);
32
+ await page.loading();
33
+ await page.loading();
34
+ await page.loading();
35
+ await page.buttonComponent("打印条码").click();
36
+ await page.loading();
37
+ await page.inputComponent(null,"读卡用F8或←").input("000002319",Key.ENTER);
38
+ await page.blockComponent("//*[@class='mzcj-list-history-ul-bottom']").moveMouseTo();
39
+ await page.textComponent("取消绑定").click();
40
+ await page.dialogComponent("取消绑定原因").waitUntilBeVisible();
41
+ await page.dialogComponent("取消绑定原因").inputComponent().input("111");
42
+ await page.dialogComponent("取消绑定原因").buttonComponent("确 定").click();
43
+ await page.dialogComponent("取消绑定原因").waitUntilBeVisible();
44
+ await page.loading();
45
+ })
46
+
47
+ test("003", async () => {
48
+ const page = new Page(browser);
49
+ await page.inputComponent(null, "请输入登录账户").input("yj");
50
+ await page.inputComponent(null, "请输入登录密码").input("1");
51
+ await page.buttonComponent().click();
52
+ await page.menuComponent().select("标本采集","标本查询");
53
+ await page.browser.sleep(1000);
54
+ await page.inputComponent("扫描条码").input("000002319");
55
+ await page.checkboxComponent("病人类型").select("门诊");
56
+ await page.buttonComponent("查询标本列表").click();
57
+ let bbtm = await page.blockComponent("//*[@class='query-table-bottom']//input").getValue();
58
+ await page.menuComponent().select("日常操作","标本签收");
59
+ await page.inputComponent("扫描条码").input(bbtm, Key.ENTER);
60
+ let td = await page.tableComponent().getTableData();
61
+ console.log(td);
62
+ await page.tableComponent().blockComponent(1).textComponent("撤销").click();
63
+ await page.dialogComponent("撤销签收").waitUntilBeVisible();
64
+ await page.dialogComponent("撤销签收").selectComponent("受话人").select("1");
65
+ await page.dialogComponent("撤销签收").inputComponent("原因").input("1");
66
+ await page.dialogComponent("撤销签收").buttonComponent("确 定").click();
67
+ await page.dialogComponent("撤销签收").waitUntilBeNotVisible();
68
+ })
69
+
@@ -0,0 +1,9 @@
1
+ {
2
+ "url": "http://172.17.1.196/frame/#/index",
3
+ "user": {
4
+ "admin": {
5
+ "用户名": "yj",
6
+ "密码": "1"
7
+ }
8
+ }
9
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@winning-test/component",
3
- "version": "0.0.77",
3
+ "version": "0.0.78",
4
4
  "description": "",
5
5
  "main": "",
6
6
  "scripts": {
@@ -49,10 +49,10 @@ class TableComponent extends require("./Component") {
49
49
  titles[i] = (await titles[i].getText(true)).trim() || `#${String(i).padStart(3, "0")}`;
50
50
  }
51
51
  // 处理表体
52
- xpath = `(${this.getXpath()}${this._createBodyXapth()})[1]//tr`;
52
+ xpath = `(${this.getXpath()}${this._createBodyXapth()})[1]//tr[not (ancestor-or-self::*[contains(@style,'display: none')])]`;
53
53
  let trs = await this.browser.findElements(xpath);
54
54
  for (let i = 0; i < trs.length; i++) {
55
- xpath = `(${this.getXpath()}${this._createBodyXapth()}//tr)[${i + 1}]/td`;
55
+ xpath = `(${this.getXpath()}${this._createBodyXapth()}//tr[not (ancestor-or-self::*[contains(@style,'display: none')])])[${i + 1}]/td`;
56
56
  let tds = await this.browser.findElements(xpath);
57
57
  let row = {};
58
58
  for (let j = 0; j < tds.length; j++) {