automation_model 1.0.24 → 1.0.25
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/auto_page.js +17 -59
- package/bin/stable_browser.js +1 -1
- package/package.json +1 -1
package/bin/auto_page.js
CHANGED
|
@@ -1,64 +1,22 @@
|
|
|
1
1
|
import { getContext } from "./init_browser.js";
|
|
2
|
-
import { StableBrowser } from "./stable_browser.js";
|
|
3
|
-
class AutoPage {
|
|
4
|
-
constructor() {
|
|
5
|
-
this.name = null;
|
|
6
|
-
this.path = null;
|
|
7
|
-
this.elements = {};
|
|
8
|
-
this.context = null;
|
|
9
|
-
this.login_required = false;
|
|
10
|
-
this.url_navigate = true;
|
|
11
|
-
this.stable = null;
|
|
12
|
-
}
|
|
13
2
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
this.elements[name] = locator;
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* init context
|
|
28
|
-
*/
|
|
29
|
-
static async init(navigate = true, headless = false) {
|
|
30
|
-
const instance = new this();
|
|
31
|
-
instance.context = await getContext(null, headless);
|
|
32
|
-
instance.page = instance.context.page;
|
|
33
|
-
instance.browser = instance.context.browser;
|
|
34
|
-
instance.stable = instance.context.stable;
|
|
35
|
-
if (navigate) {
|
|
36
|
-
await instance.navigate();
|
|
37
|
-
}
|
|
38
|
-
return instance;
|
|
3
|
+
let context = null;
|
|
4
|
+
const navigate = async (path = "") => {
|
|
5
|
+
//console.log("navigate", this.context.environment.baseUrl + this.path);
|
|
6
|
+
await context.stable.goto(context.environment.baseUrl + path);
|
|
7
|
+
await context.stable.waitForPageLoad();
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const initContext = async (path, doNavigate = true, headless = false) => {
|
|
11
|
+
if (context) {
|
|
12
|
+
return context;
|
|
39
13
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
instance.page = instance.context.page;
|
|
44
|
-
instance.browser = instance.context.browser;
|
|
45
|
-
instance.environment = instance.context.environment;
|
|
46
|
-
instance.stable = instance.context.stable;
|
|
47
|
-
if (navigate) {
|
|
48
|
-
await instance.navigate();
|
|
49
|
-
}
|
|
50
|
-
return instance;
|
|
14
|
+
context = await getContext(null, headless);
|
|
15
|
+
if (doNavigate) {
|
|
16
|
+
await navigate(path);
|
|
51
17
|
}
|
|
52
18
|
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
*/
|
|
58
|
-
async navigate() {
|
|
59
|
-
//console.log("navigate", this.context.environment.baseUrl + this.path);
|
|
60
|
-
await this.stable.goto(this.context.environment.baseUrl + this.path);
|
|
61
|
-
await this.stable.waitForPageLoad();
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
export { AutoPage };
|
|
19
|
+
return context;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export { initContext, navigate };
|
package/bin/stable_browser.js
CHANGED
|
@@ -94,7 +94,7 @@ class StableBrowser {
|
|
|
94
94
|
return locators[0];
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
|
-
throw new Error("failed to locate first element no elements found");
|
|
97
|
+
throw new Error("failed to locate first element no elements found, " + JSON.stringify(info));
|
|
98
98
|
}
|
|
99
99
|
|
|
100
100
|
async click(selector, options = {}) {
|