automation_model 1.0.63 → 1.0.64
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/.github/workflows/npm-publish.yml +38 -0
- package/.vscode/launch.json +30 -0
- package/README.md +3 -0
- package/ai_config.json +53 -0
- package/build/auto_page.d.ts +5 -0
- package/build/auto_page.js +56 -0
- package/build/auto_page.js.map +1 -0
- package/build/browser_manager.d.ts +28 -0
- package/build/browser_manager.js +72 -0
- package/build/browser_manager.js.map +1 -0
- package/build/environment.d.ts +23 -0
- package/build/environment.js +12 -0
- package/build/environment.js.map +1 -0
- package/build/index.js +7 -0
- package/build/index.js.map +1 -0
- package/build/init_browser.d.ts +7 -0
- package/build/init_browser.js +59 -0
- package/build/init_browser.js.map +1 -0
- package/build/locator.d.ts +15 -0
- package/build/locator.js +172 -0
- package/build/locator.js.map +1 -0
- package/build/stable_browser.d.ts +26 -0
- package/build/stable_browser.js +526 -0
- package/build/stable_browser.js.map +1 -0
- package/build/table_analyze.d.ts +3 -0
- package/build/table_analyze.js +64 -0
- package/build/table_analyze.js.map +1 -0
- package/build/test_context.d.ts +13 -0
- package/build/test_context.js +12 -0
- package/build/test_context.js.map +1 -0
- package/env.json +3 -0
- package/package.json +14 -11
- package/{bin/auto_page.js → src/auto_page.ts} +58 -57
- package/{bin/browser_manager.js → src/browser_manager.ts} +87 -78
- package/src/environment.ts +24 -0
- package/{bin/index.js → src/index.ts} +6 -6
- package/src/init_browser.ts +65 -0
- package/{bin/locator.js → src/locator.ts} +173 -159
- package/{bin/stable_browser.js → src/stable_browser.ts} +523 -520
- package/{bin/table_analyze.js → src/table_analyze.ts} +69 -61
- package/src/test_context.ts +16 -0
- package/tests/create_new_repository.test.js +62 -0
- package/tests/debug.test.js +41 -0
- package/tests/gmail_login.test.js +39 -0
- package/tests/launch_page.test.js +32 -0
- package/tests/navigate_to_new_repository_page.test.js +45 -0
- package/tsconfig.json +110 -0
- package/bin/auto_page.d.ts +0 -3
- package/bin/browser_manager.d.ts +0 -16
- package/bin/environment.d.ts +0 -4
- package/bin/environment.js +0 -9
- package/bin/init_browser.d.ts +0 -3
- package/bin/init_browser.js +0 -61
- package/bin/locator.d.ts +0 -21
- package/bin/stable_browser.d.ts +0 -61
- package/bin/table_analyze.d.ts +0 -1
- package/bin/test_context.d.ts +0 -6
- package/bin/test_context.js +0 -9
- /package/{bin → build}/index.d.ts +0 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { BrowserContext, Page, Browser as PlaywrightBrowser } from "playwright";
|
|
2
|
+
import { Environment } from "./environment.js";
|
|
3
|
+
import { StableBrowser } from "./stable_browser.js";
|
|
4
|
+
declare class TestContext {
|
|
5
|
+
stable: StableBrowser | null;
|
|
6
|
+
browser: PlaywrightBrowser | null;
|
|
7
|
+
playContext: BrowserContext | null;
|
|
8
|
+
page: Page | null;
|
|
9
|
+
environment: Environment | null;
|
|
10
|
+
reportFolder: string | null;
|
|
11
|
+
constructor();
|
|
12
|
+
}
|
|
13
|
+
export { TestContext };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
class TestContext {
|
|
2
|
+
constructor() {
|
|
3
|
+
this.stable = null;
|
|
4
|
+
this.browser = null;
|
|
5
|
+
this.playContext = null;
|
|
6
|
+
this.page = null;
|
|
7
|
+
this.environment = null;
|
|
8
|
+
this.reportFolder = null;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export { TestContext };
|
|
12
|
+
//# sourceMappingURL=test_context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"test_context.js","sourceRoot":"","sources":["../src/test_context.ts"],"names":[],"mappings":"AAIA,MAAM,WAAW;IAOf;QANA,WAAM,GAAuB,IAAI,CAAA;QACjC,YAAO,GAA2B,IAAI,CAAA;QACtC,gBAAW,GAA0B,IAAI,CAAA;QACzC,SAAI,GAAgB,IAAI,CAAA;QACxB,gBAAW,GAAqB,IAAI,CAAA;QACpC,iBAAY,GAAgB,IAAI,CAAA;IAGhC,CAAC;CACF;AACD,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
package/env.json
ADDED
package/package.json
CHANGED
|
@@ -1,28 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "automation_model",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.64",
|
|
4
4
|
"description": "An automation infrastructure module to be use for generative AI automation projects.",
|
|
5
|
-
"main": "
|
|
5
|
+
"main": "build/index.js",
|
|
6
6
|
"type": "module",
|
|
7
|
-
"types": "
|
|
7
|
+
"types": "build/index.d.ts",
|
|
8
8
|
"directories": {
|
|
9
9
|
"lib": "lib"
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
12
|
+
"compile": "tsc",
|
|
13
|
+
"pack": "mkdir build && mkdir build/bin && cp ./src/auto_page.js ./build/bin/auto_page.js && cp ./src/environment.js ./build/bin/environment.js && cp ./src/browser_manager.js ./build/bin/browser_manager.js && cp ./src/test_context.js ./build/bin/test_context.js && cp ./src/init_browser.js ./build/bin/init_browser.js && cp ./src/stable_browser.js ./build/bin/stable_browser.js && cp ./package.json ./build/package.json",
|
|
14
|
+
"clean": "rimraf -g build && rimraf -g types",
|
|
15
|
+
"build": "npm run clean && npm run compile",
|
|
16
|
+
"test": "node tests/debug.test.js",
|
|
17
|
+
"types": "tsc --declaration --allowJs --emitDeclarationOnly --outDir types"
|
|
17
18
|
},
|
|
18
19
|
"author": "",
|
|
19
20
|
"license": "ISC",
|
|
20
21
|
"dependencies": {
|
|
21
|
-
"
|
|
22
|
-
"playwright": "^1.33.0",
|
|
22
|
+
"playwright": "^1.39.0",
|
|
23
23
|
"regex-parser": "^2.2.11"
|
|
24
24
|
},
|
|
25
25
|
"devDependencies": {
|
|
26
|
+
"@playwright/test": "^1.40.0",
|
|
27
|
+
"@types/node": "^20.9.3",
|
|
28
|
+
"rimraf": "^5.0.5",
|
|
26
29
|
"typescript": "^5.2.2"
|
|
27
30
|
}
|
|
28
|
-
}
|
|
31
|
+
}
|
|
@@ -1,57 +1,58 @@
|
|
|
1
|
-
import { browserManager } from "./browser_manager.js";
|
|
2
|
-
import { getContext } from "./init_browser.js";
|
|
3
|
-
import fs from "fs";
|
|
4
|
-
import path from "path";
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
await context
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
1
|
+
import { browserManager } from "./browser_manager.js";
|
|
2
|
+
import { getContext } from "./init_browser.js";
|
|
3
|
+
import fs from "fs";
|
|
4
|
+
import path from "path";
|
|
5
|
+
import type { TestContext } from "./test_context.js";
|
|
6
|
+
let context:TestContext|null = null;
|
|
7
|
+
const navigate = async (path = "") => {
|
|
8
|
+
let url = null;
|
|
9
|
+
if (path === null) {
|
|
10
|
+
url = context!.environment!.baseUrl!;
|
|
11
|
+
} else {
|
|
12
|
+
url = new URL(path, context!.environment!.baseUrl).href;
|
|
13
|
+
}
|
|
14
|
+
await context!.stable!.goto(url);
|
|
15
|
+
await context!.stable!.waitForPageLoad();
|
|
16
|
+
};
|
|
17
|
+
const _findEmptyFolder = (folder?:string) => {
|
|
18
|
+
if (!folder) {
|
|
19
|
+
folder = "./runs";
|
|
20
|
+
}
|
|
21
|
+
if (!fs.existsSync(folder)) {
|
|
22
|
+
fs.mkdirSync(folder);
|
|
23
|
+
}
|
|
24
|
+
let nextIndex = 1;
|
|
25
|
+
while (fs.existsSync(path.join(folder, nextIndex.toString()))) {
|
|
26
|
+
nextIndex++;
|
|
27
|
+
}
|
|
28
|
+
return path.join(folder, nextIndex.toString());
|
|
29
|
+
};
|
|
30
|
+
const initContext = async (path:string, doNavigate = true, headless = false, world:any = null) => {
|
|
31
|
+
if (context) {
|
|
32
|
+
return context;
|
|
33
|
+
}
|
|
34
|
+
context = await getContext(null, headless);
|
|
35
|
+
|
|
36
|
+
if (world) {
|
|
37
|
+
world.screenshot = true;
|
|
38
|
+
const reportFolder = _findEmptyFolder();
|
|
39
|
+
if (world.attach) {
|
|
40
|
+
world.attach(reportFolder, { mediaType: "text/plain" });
|
|
41
|
+
}
|
|
42
|
+
world.screenshotPath = reportFolder;
|
|
43
|
+
context.reportFolder = reportFolder;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (doNavigate) {
|
|
47
|
+
await navigate(path);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return context;
|
|
51
|
+
};
|
|
52
|
+
const closeContext = async () => {
|
|
53
|
+
if (context && context.browser) {
|
|
54
|
+
await browserManager.closeBrowser(context.browser);
|
|
55
|
+
}
|
|
56
|
+
context = null;
|
|
57
|
+
};
|
|
58
|
+
export { initContext, navigate, closeContext };
|
|
@@ -1,78 +1,87 @@
|
|
|
1
|
-
import { chromium } from "playwright";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
this.
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
1
|
+
import { chromium, Browser as PlaywrightBrowser, BrowserContext, Page, BrowserContextOptions } from "playwright";
|
|
2
|
+
import type { Cookie, LocalStorage } from "./environment.js";
|
|
3
|
+
|
|
4
|
+
type StorageState = {
|
|
5
|
+
cookies: Cookie[],
|
|
6
|
+
origins: {origin: string, localStorage: LocalStorage}[]
|
|
7
|
+
}
|
|
8
|
+
class BrowserManager {
|
|
9
|
+
constructor(public browsers: Browser[] = []) {
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
async closeAll() {
|
|
13
|
+
await Promise.all(this.browsers.map((browser) => browser.close()));
|
|
14
|
+
this.browsers = [];
|
|
15
|
+
}
|
|
16
|
+
async closeBrowser(browser?: PlaywrightBrowser |Browser) {
|
|
17
|
+
if (!browser && this.browsers.length > 0) {
|
|
18
|
+
browser = this.browsers[0];
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (browser) {
|
|
22
|
+
await browser.close();
|
|
23
|
+
for (let i = 0; i < this.browsers.length; i++) {
|
|
24
|
+
if (this.browsers[i].browser === browser || this.browsers[i] === browser) {
|
|
25
|
+
this.browsers.splice(i, 1);
|
|
26
|
+
i--;
|
|
27
|
+
break;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async createBrowser(headless = false, storageState?:StorageState) {
|
|
34
|
+
const browser = new Browser();
|
|
35
|
+
await browser.init(headless, storageState);
|
|
36
|
+
this.browsers.push(browser);
|
|
37
|
+
return browser;
|
|
38
|
+
}
|
|
39
|
+
async getBrowser(headless = false, storageState?:StorageState) {
|
|
40
|
+
if (this.browsers.length === 0) {
|
|
41
|
+
return await this.createBrowser(headless, storageState);
|
|
42
|
+
}
|
|
43
|
+
return this.browsers[0];
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
class Browser {
|
|
47
|
+
browser : PlaywrightBrowser|null;
|
|
48
|
+
context : BrowserContext | null;
|
|
49
|
+
page : Page | null;
|
|
50
|
+
constructor() {
|
|
51
|
+
this.browser = null;
|
|
52
|
+
this.context = null;
|
|
53
|
+
this.page = null;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async init(headless = false, storageState?:StorageState) {
|
|
57
|
+
this.browser = await chromium.launch({
|
|
58
|
+
headless: headless,
|
|
59
|
+
timeout: 0,
|
|
60
|
+
args: ["--ignore-https-errors"],
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
const contextOptions = !!storageState ? {storageState} : undefined
|
|
64
|
+
this.context = await this.browser.newContext(contextOptions as unknown as BrowserContextOptions);
|
|
65
|
+
this.page = await this.context.newPage();
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async close() {
|
|
69
|
+
if (this.browser !== null) {
|
|
70
|
+
await this.browser.close();
|
|
71
|
+
this.browser = null;
|
|
72
|
+
this.context = null;
|
|
73
|
+
this.page = null;
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
const browserManager = new BrowserManager();
|
|
78
|
+
|
|
79
|
+
export { browserManager };
|
|
80
|
+
export type {BrowserManager, Browser}
|
|
81
|
+
// let browser = await browserManager.createBrowser();
|
|
82
|
+
// browser.page.goto("https://www.cnn.com");
|
|
83
|
+
// let browser2 = await browserManager.createBrowser();
|
|
84
|
+
// await browser2.page.goto("https://www.google.com");
|
|
85
|
+
// // sleep for 2 seconds
|
|
86
|
+
// await new Promise((r) => setTimeout(r, 1000));
|
|
87
|
+
// await browserManager.closeAll();
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
type Cookie ={
|
|
2
|
+
name: string
|
|
3
|
+
value: string
|
|
4
|
+
domain?: string
|
|
5
|
+
path?: string
|
|
6
|
+
expires?: number
|
|
7
|
+
httpOnly?: boolean
|
|
8
|
+
secure?: boolean
|
|
9
|
+
sameSite?: string
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
type LocalStorage = Record<string, string>
|
|
13
|
+
|
|
14
|
+
class Environment {
|
|
15
|
+
cookies:Cookie[] = []
|
|
16
|
+
origins:{origin:string, localStorage:LocalStorage}[] = []
|
|
17
|
+
constructor(public baseUrl?: string) {
|
|
18
|
+
}
|
|
19
|
+
setBaseUrl(url: string) {
|
|
20
|
+
this.baseUrl = url;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
export { Environment };
|
|
24
|
+
export type { Cookie, LocalStorage };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export * from "./auto_page.js";
|
|
2
|
-
export * from "./init_browser.js";
|
|
3
|
-
export * from "./stable_browser.js";
|
|
4
|
-
export * from "./environment.js";
|
|
5
|
-
export * from "./auto_page.js";
|
|
6
|
-
export * from "./browser_manager.js";
|
|
1
|
+
export * from "./auto_page.js";
|
|
2
|
+
export * from "./init_browser.js";
|
|
3
|
+
export * from "./stable_browser.js";
|
|
4
|
+
export * from "./environment.js";
|
|
5
|
+
export * from "./auto_page.js";
|
|
6
|
+
export * from "./browser_manager.js";
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import fs from "node:fs";
|
|
2
|
+
import { Environment } from "./environment.js";
|
|
3
|
+
import { browserManager } from "./browser_manager.js";
|
|
4
|
+
import { TestContext } from "./test_context.js";
|
|
5
|
+
import { StableBrowser } from "./stable_browser.js";
|
|
6
|
+
import { Browser as PlaywrightBrowser } from "playwright";
|
|
7
|
+
import { Browser } from "./browser_manager.js";
|
|
8
|
+
|
|
9
|
+
// let environment = null;
|
|
10
|
+
|
|
11
|
+
// init browser create context and page, if context and page are not null
|
|
12
|
+
const getContext = async function (environment: Environment|null, headless = false, logger?: null) {
|
|
13
|
+
if (environment === null) {
|
|
14
|
+
environment = initEnvironment();
|
|
15
|
+
}
|
|
16
|
+
const {cookies, origins} = environment;
|
|
17
|
+
const storageState = {cookies, origins};
|
|
18
|
+
let browser = await browserManager.getBrowser(headless, storageState);
|
|
19
|
+
let context = new TestContext();
|
|
20
|
+
context.browser = browser.browser;
|
|
21
|
+
context.playContext = browser.context;
|
|
22
|
+
context.page = browser.page;
|
|
23
|
+
context.environment = environment;
|
|
24
|
+
|
|
25
|
+
context.stable = new StableBrowser(context.browser!, context.page!, logger);
|
|
26
|
+
// await _initCookies(context);
|
|
27
|
+
return context;
|
|
28
|
+
};
|
|
29
|
+
// const _initCookies = async function (context) {
|
|
30
|
+
// if (context.environment.cookies) {
|
|
31
|
+
// const cookies = [];
|
|
32
|
+
// for (let i = 0; i < context.environment.cookies.length; i++) {
|
|
33
|
+
// const cookie = context.environment.cookies[i];
|
|
34
|
+
// if (cookie.expires && cookie.expires == "undefined") {
|
|
35
|
+
// delete cookie.expires;
|
|
36
|
+
// }
|
|
37
|
+
// cookies.push(cookie);
|
|
38
|
+
// }
|
|
39
|
+
// await context.playContext.addCookies(cookies);
|
|
40
|
+
// }
|
|
41
|
+
// };
|
|
42
|
+
|
|
43
|
+
const closeBrowser = async function (browser? :Browser|PlaywrightBrowser) {
|
|
44
|
+
await browserManager.closeBrowser(browser);
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const initEnvironment = function () {
|
|
48
|
+
// if (environment === null) {
|
|
49
|
+
const environment = new Environment();
|
|
50
|
+
try {
|
|
51
|
+
const data = fs.readFileSync("env.json", "utf8");
|
|
52
|
+
//console.log("data", data);
|
|
53
|
+
const envObject = JSON.parse(data);
|
|
54
|
+
//console.log("envObject", envObject);
|
|
55
|
+
Object.assign(environment, envObject);
|
|
56
|
+
//console.log("env", environment);
|
|
57
|
+
console.log("Base url: " + environment.baseUrl);
|
|
58
|
+
} catch (err) {
|
|
59
|
+
console.error("Error reading env.json", err);
|
|
60
|
+
}
|
|
61
|
+
// }
|
|
62
|
+
return environment;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export { getContext, closeBrowser };
|