automation_model 1.0.21 → 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 +12 -12
- package/package.json +1 -1
package/bin/stable_browser.js
CHANGED
|
@@ -81,15 +81,14 @@ class StableBrowser {
|
|
|
81
81
|
info.log.push("try selector " + i);
|
|
82
82
|
try {
|
|
83
83
|
let element = await this._locate(selector[i], this.page, info);
|
|
84
|
-
|
|
85
|
-
await element.screenshot({ path: options.screenshotPath });
|
|
86
|
-
}
|
|
84
|
+
await this._screenShot(options);
|
|
87
85
|
await element.click({ timeout: 10000 });
|
|
88
86
|
return info;
|
|
89
87
|
} catch (e) {
|
|
90
88
|
if (i === selector.length - 1) {
|
|
91
89
|
this.logger.error("click failed " + JSON.stringify(info));
|
|
92
90
|
Object.assign(e, { info: info });
|
|
91
|
+
await this._screenShot(options);
|
|
93
92
|
throw e;
|
|
94
93
|
}
|
|
95
94
|
this.logger.info("click failed, will try next selector");
|
|
@@ -106,9 +105,7 @@ class StableBrowser {
|
|
|
106
105
|
info.log.push("try selector " + i);
|
|
107
106
|
try {
|
|
108
107
|
let element = await this._locate(selector[i], this.page, info);
|
|
109
|
-
|
|
110
|
-
await element.screenshot({ path: options.screenshotPath });
|
|
111
|
-
}
|
|
108
|
+
await this._screenShot(options);
|
|
112
109
|
await element.fill(value, { timeout: 10000 });
|
|
113
110
|
await element.dispatchEvent("change");
|
|
114
111
|
return info;
|
|
@@ -116,12 +113,18 @@ class StableBrowser {
|
|
|
116
113
|
if (i === selector.length - 1) {
|
|
117
114
|
this.logger.error("fill failed " + JSON.stringify(info));
|
|
118
115
|
Object.assign(e, { info: info });
|
|
116
|
+
await this._screenShot(options);
|
|
119
117
|
throw e;
|
|
120
118
|
}
|
|
121
119
|
this.logger.info("click failed, will try next selector");
|
|
122
120
|
}
|
|
123
121
|
}
|
|
124
122
|
}
|
|
123
|
+
async _screenShot(options = {}) {
|
|
124
|
+
if (options.screenshot) {
|
|
125
|
+
await this.page.screenshot({ path: options.screenshotPath });
|
|
126
|
+
}
|
|
127
|
+
}
|
|
125
128
|
async verifyElementExistInPage(selector, options = {}) {
|
|
126
129
|
const info = {};
|
|
127
130
|
info.log = [];
|
|
@@ -130,15 +133,14 @@ class StableBrowser {
|
|
|
130
133
|
for (let i = 0; i < selector.length; i++) {
|
|
131
134
|
try {
|
|
132
135
|
const element = await this._locate(selector[0], this.page, info);
|
|
133
|
-
|
|
134
|
-
await element.screenshot({ path: options.screenshotPath });
|
|
135
|
-
}
|
|
136
|
+
await this._screenShot(options);
|
|
136
137
|
await expect(element).toHaveCount(1, { timeout: 10000 });
|
|
137
138
|
return info;
|
|
138
139
|
} catch (e) {
|
|
139
140
|
if (i === selector.length - 1) {
|
|
140
141
|
this.logger.error("verify failed " + JSON.stringify(info));
|
|
141
142
|
Object.assign(e, { info: info });
|
|
143
|
+
await this._screenShot(options);
|
|
142
144
|
throw e;
|
|
143
145
|
}
|
|
144
146
|
this.logger.info("click failed, will try next selector");
|
|
@@ -158,9 +160,7 @@ class StableBrowser {
|
|
|
158
160
|
console.log("waitForPageLoad error, ignored");
|
|
159
161
|
}
|
|
160
162
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
161
|
-
|
|
162
|
-
await element.screenshot({ path: options.screenshotPath });
|
|
163
|
-
}
|
|
163
|
+
await this._screenShot(options);
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
export { StableBrowser };
|