automation_model 1.0.19 → 1.0.21
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,7 +80,11 @@ 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
|
+
if (options.screenshot) {
|
|
85
|
+
await element.screenshot({ path: options.screenshotPath });
|
|
86
|
+
}
|
|
87
|
+
await element.click({ timeout: 10000 });
|
|
84
88
|
return info;
|
|
85
89
|
} catch (e) {
|
|
86
90
|
if (i === selector.length - 1) {
|
|
@@ -92,7 +96,7 @@ class StableBrowser {
|
|
|
92
96
|
}
|
|
93
97
|
}
|
|
94
98
|
}
|
|
95
|
-
async fill(selector, value) {
|
|
99
|
+
async fill(selector, value, options = {}) {
|
|
96
100
|
const info = {};
|
|
97
101
|
info.log = [];
|
|
98
102
|
info.operation = "fill";
|
|
@@ -102,6 +106,9 @@ class StableBrowser {
|
|
|
102
106
|
info.log.push("try selector " + i);
|
|
103
107
|
try {
|
|
104
108
|
let element = await this._locate(selector[i], this.page, info);
|
|
109
|
+
if (options.screenshot) {
|
|
110
|
+
await element.screenshot({ path: options.screenshotPath });
|
|
111
|
+
}
|
|
105
112
|
await element.fill(value, { timeout: 10000 });
|
|
106
113
|
await element.dispatchEvent("change");
|
|
107
114
|
return info;
|
|
@@ -115,7 +122,7 @@ class StableBrowser {
|
|
|
115
122
|
}
|
|
116
123
|
}
|
|
117
124
|
}
|
|
118
|
-
async verifyElementExistInPage(selector) {
|
|
125
|
+
async verifyElementExistInPage(selector, options = {}) {
|
|
119
126
|
const info = {};
|
|
120
127
|
info.log = [];
|
|
121
128
|
info.operation = "verify";
|
|
@@ -123,6 +130,9 @@ class StableBrowser {
|
|
|
123
130
|
for (let i = 0; i < selector.length; i++) {
|
|
124
131
|
try {
|
|
125
132
|
const element = await this._locate(selector[0], this.page, info);
|
|
133
|
+
if (options.screenshot) {
|
|
134
|
+
await element.screenshot({ path: options.screenshotPath });
|
|
135
|
+
}
|
|
126
136
|
await expect(element).toHaveCount(1, { timeout: 10000 });
|
|
127
137
|
return info;
|
|
128
138
|
} catch (e) {
|
|
@@ -137,7 +147,7 @@ class StableBrowser {
|
|
|
137
147
|
|
|
138
148
|
//await expect(element !== undefined).toBeTruthy();
|
|
139
149
|
}
|
|
140
|
-
async waitForPageLoad() {
|
|
150
|
+
async waitForPageLoad(options = {}) {
|
|
141
151
|
try {
|
|
142
152
|
await Promise.all([
|
|
143
153
|
this.page.waitForLoadState("networkidle"),
|
|
@@ -148,6 +158,9 @@ class StableBrowser {
|
|
|
148
158
|
console.log("waitForPageLoad error, ignored");
|
|
149
159
|
}
|
|
150
160
|
await new Promise((resolve) => setTimeout(resolve, 2000));
|
|
161
|
+
if (options.screenshot) {
|
|
162
|
+
await element.screenshot({ path: options.screenshotPath });
|
|
163
|
+
}
|
|
151
164
|
}
|
|
152
165
|
}
|
|
153
166
|
export { StableBrowser };
|