@winning-test/component 0.0.101 → 0.0.103
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/TechBookCenter/component/BlockComponent.js +173 -0
- package/TechBookCenter/component/ButtonComponent.js +26 -0
- package/TechBookCenter/component/CheckboxComponent.js +46 -0
- package/TechBookCenter/component/Component.js +109 -0
- package/TechBookCenter/component/DialogComponent.js +26 -0
- package/TechBookCenter/component/InputComponent.js +31 -0
- package/TechBookCenter/component/MenuComponent.js +36 -0
- package/TechBookCenter/component/MessageComponent.js +87 -0
- package/TechBookCenter/component/RadioComponent.js +41 -0
- package/TechBookCenter/component/SelectComponent.js +43 -0
- package/TechBookCenter/component/TableComponent.js +113 -0
- package/TechBookCenter/component/TextComponent.js +23 -0
- package/TechBookCenter/page/Page.js +172 -0
- package/package.json +1 -1
- package/rfds5.6/component/BlockComponent.js +248 -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 +47 -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 +238 -0
- package/rfds5.6/test/component.test.js +64 -0
- package/rfds5.6/test/component.test.json +13 -0
|
@@ -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;
|
package/package.json
CHANGED
|
@@ -0,0 +1,248 @@
|
|
|
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
|
+
* @param {Stirng} text 文本
|
|
130
|
+
* @returns 消息组件
|
|
131
|
+
*/
|
|
132
|
+
messageComponent(text) {
|
|
133
|
+
let that = this;
|
|
134
|
+
class MessageComponent extends require("./MessageComponent") {
|
|
135
|
+
_createRootXpath() {
|
|
136
|
+
return that.getXpath();
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return new MessageComponent(this.browser, text);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* 获取单选组件
|
|
144
|
+
* @param {Stirng} label 标签
|
|
145
|
+
* @returns 单选组件
|
|
146
|
+
*/
|
|
147
|
+
radioComponent(label) {
|
|
148
|
+
let that = this;
|
|
149
|
+
class RadioComponent extends require("./RadioComponent") {
|
|
150
|
+
_createRootXpath() {
|
|
151
|
+
return that.getXpath();
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
return new RadioComponent(this.browser, label);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* 获取选择器组件
|
|
159
|
+
* @param {String} placeholder 背景文字
|
|
160
|
+
* @param {String} label 标签
|
|
161
|
+
* @returns 选择器组件
|
|
162
|
+
*/
|
|
163
|
+
selectComponent(placeholder, label, forceMulti) {
|
|
164
|
+
let that = this;
|
|
165
|
+
class SelectComponent extends require("./SelectComponent") {
|
|
166
|
+
_createRootXpath() {
|
|
167
|
+
return that.getXpath();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return new SelectComponent(this.browser, placeholder, label, forceMulti);
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* 获取开关组件
|
|
175
|
+
* @param {String} label 标签
|
|
176
|
+
* @returns 开关组件
|
|
177
|
+
*/
|
|
178
|
+
switchComponent(label) {
|
|
179
|
+
let that = this;
|
|
180
|
+
class SwitchComponent extends require("./SwitchComponent") {
|
|
181
|
+
_createRootXpath() {
|
|
182
|
+
return that.getXpath();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return new SwitchComponent(this.browser, label);
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* 获取表格组件
|
|
190
|
+
* @returns 表格组件
|
|
191
|
+
*/
|
|
192
|
+
tableComponent() {
|
|
193
|
+
let that = this;
|
|
194
|
+
class TableComponent extends require("./TableComponent") {
|
|
195
|
+
_createRootXpath() {
|
|
196
|
+
return that.getXpath();
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
return new TableComponent(this.browser);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* 获取多行文本输入组件
|
|
204
|
+
* @param {String} textarea 多行文本输入
|
|
205
|
+
* @returns 多行文本输入组件
|
|
206
|
+
*/
|
|
207
|
+
textareaComponent(placeholder, label) {
|
|
208
|
+
let that = this;
|
|
209
|
+
class TextareaComponent extends require("./TextareaComponent") {
|
|
210
|
+
_createRootXpath() {
|
|
211
|
+
return that.getXpath();
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
return new TextareaComponent(this.browser, placeholder, label);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* 获取文本组件
|
|
219
|
+
* @param {String} text 文本
|
|
220
|
+
* @returns 文本组件
|
|
221
|
+
*/
|
|
222
|
+
textComponent(text) {
|
|
223
|
+
let that = this;
|
|
224
|
+
class TextComponent extends require("./TextComponent") {
|
|
225
|
+
_createRootXpath() {
|
|
226
|
+
return that.getXpath();
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
return new TextComponent(this.browser, text);
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* 获取顶部菜单组件
|
|
234
|
+
* @returns 顶部菜单组件
|
|
235
|
+
*/
|
|
236
|
+
topMenuComponent(firstItem) {
|
|
237
|
+
let that = this;
|
|
238
|
+
class TopMenuComponent extends require("./TopMenuComponent") {
|
|
239
|
+
_createRootXpath() {
|
|
240
|
+
return that.getXpath();
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
return new TopMenuComponent(this.browser, firstItem);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
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;
|