automation_model 1.0.20 → 1.0.22
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/bin/stable_browser.js +18 -5
- package/package.json +1 -1
package/bin/stable_browser.js
CHANGED
|
@@ -72,7 +72,7 @@ class StableBrowser {
|
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
async click(selector) {
|
|
75
|
+
async click(selector, options = {}) {
|
|
76
76
|
const info = {};
|
|
77
77
|
info.log = [];
|
|
78
78
|
info.operation = "click";
|
|
@@ -80,19 +80,22 @@ class StableBrowser {
|
|
|
80
80
|
for (let i = 0; i < selector.length; i++) {
|
|
81
81
|
info.log.push("try selector " + i);
|
|
82
82
|
try {
|
|
83
|
-
|
|
83
|
+
let element = await this._locate(selector[i], this.page, info);
|
|
84
|
+
await this._screenShot(options);
|
|
85
|
+
await element.click({ timeout: 10000 });
|
|
84
86
|
return info;
|
|
85
87
|
} catch (e) {
|
|
86
88
|
if (i === selector.length - 1) {
|
|
87
89
|
this.logger.error("click failed " + JSON.stringify(info));
|
|
88
90
|
Object.assign(e, { info: info });
|
|
91
|
+
await this._screenShot(options);
|
|
89
92
|
throw e;
|
|
90
93
|
}
|
|
91
94
|
this.logger.info("click failed, will try next selector");
|
|
92
95
|
}
|
|
93
96
|
}
|
|
94
97
|
}
|
|
95
|
-
async fill(selector, value) {
|
|
98
|
+
async fill(selector, value, options = {}) {
|
|
96
99
|
const info = {};
|
|
97
100
|
info.log = [];
|
|
98
101
|
info.operation = "fill";
|
|
@@ -102,6 +105,7 @@ class StableBrowser {
|
|
|
102
105
|
info.log.push("try selector " + i);
|
|
103
106
|
try {
|
|
104
107
|
let element = await this._locate(selector[i], this.page, info);
|
|
108
|
+
await this._screenShot(options);
|
|
105
109
|
await element.fill(value, { timeout: 10000 });
|
|
106
110
|
await element.dispatchEvent("change");
|
|
107
111
|
return info;
|
|
@@ -109,13 +113,19 @@ class StableBrowser {
|
|
|
109
113
|
if (i === selector.length - 1) {
|
|
110
114
|
this.logger.error("fill failed " + JSON.stringify(info));
|
|
111
115
|
Object.assign(e, { info: info });
|
|
116
|
+
await this._screenShot(options);
|
|
112
117
|
throw e;
|
|
113
118
|
}
|
|
114
119
|
this.logger.info("click failed, will try next selector");
|
|
115
120
|
}
|
|
116
121
|
}
|
|
117
122
|
}
|
|
118
|
-
async
|
|
123
|
+
async _screenShot(options = {}) {
|
|
124
|
+
if (options.screenshot) {
|
|
125
|
+
await this.page.screenshot({ path: options.screenshotPath });
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
async verifyElementExistInPage(selector, options = {}) {
|
|
119
129
|
const info = {};
|
|
120
130
|
info.log = [];
|
|
121
131
|
info.operation = "verify";
|
|
@@ -123,12 +133,14 @@ class StableBrowser {
|
|
|
123
133
|
for (let i = 0; i < selector.length; i++) {
|
|
124
134
|
try {
|
|
125
135
|
const element = await this._locate(selector[0], this.page, info);
|
|
136
|
+
await this._screenShot(options);
|
|
126
137
|
await expect(element).toHaveCount(1, { timeout: 10000 });
|
|
127
138
|
return info;
|
|
128
139
|
} catch (e) {
|
|
129
140
|
if (i === selector.length - 1) {
|
|
130
141
|
this.logger.error("verify failed " + JSON.stringify(info));
|
|
131
142
|
Object.assign(e, { info: info });
|
|
143
|
+
await this._screenShot(options);
|
|
132
144
|
throw e;
|
|
133
145
|
}
|
|
134
146
|
this.logger.info("click failed, will try next selector");
|
|
@@ -137,7 +149,7 @@ class StableBrowser {
|
|
|
137
149
|
|
|
138
150
|
//await expect(element !== undefined).toBeTruthy();
|
|
139
151
|
}
|
|
140
|
-
async waitForPageLoad() {
|
|
152
|
+
async waitForPageLoad(options = {}) {
|
|
141
153
|
try {
|
|
142
154
|
await Promise.all([
|
|
143
155
|
this.page.waitForLoadState("networkidle"),
|
|
@@ -148,6 +160,7 @@ class StableBrowser {
|
|
|
148
160
|
console.log("waitForPageLoad error, ignored");
|
|
149
161
|
}
|
|
150
162
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
163
|
+
await this._screenShot(options);
|
|
151
164
|
}
|
|
152
165
|
}
|
|
153
166
|
export { StableBrowser };
|