@midscene/cli 0.3.0 → 0.3.1-beta-20240821105917.0

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2024-present Midscene.js
3
+ Copyright (c) 2024-present Bytedance, Inc. and its affiliates.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
18
  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
19
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
20
  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
21
+ SOFTWARE.
package/dist/es/help.js CHANGED
@@ -9,7 +9,7 @@ var require_package = __commonJS({
9
9
  module.exports = {
10
10
  name: "@midscene/cli",
11
11
  description: "Cli for Midscene.js",
12
- version: "0.3.0",
12
+ version: "0.3.1-beta-20240821105917.0",
13
13
  "jsnext:source": "./src/index.ts",
14
14
  main: "./dist/lib/index.js",
15
15
  bin: {
@@ -29,7 +29,7 @@ var require_package = __commonJS({
29
29
  dependencies: {
30
30
  "@midscene/web": "workspace:*",
31
31
  "ora-classic": "5.4.2",
32
- puppeteer: "^22.8.0",
32
+ puppeteer: "23.0.2",
33
33
  yargs: "17.7.2"
34
34
  },
35
35
  devDependencies: {
@@ -72,23 +72,24 @@ if (process.argv.indexOf("--help") !== -1) {
72
72
  --assert <assert> Perform an assert, optional
73
73
  --query-output <path> Save the result of the query to a file, this must be put before --query, optional
74
74
  --query <query> Perform a query, optional
75
+ --wait-for <assertion> Wait for a condition to be met. The timeout is set to 15 seconds. optional
75
76
  --sleep <ms> Sleep for a number of milliseconds, optional
76
77
 
77
78
  Examples:
78
79
  # headed mode (i.e. visible browser) to visit bing.com and search for 'weather today'
79
- midscene --headed --url https://wwww.bing.com --action "type 'weather today' in search box, hit enter" --sleep 3000
80
+ midscene --headed --url "https://wwww.bing.com" --action "type 'weather today' in search box, hit enter" --wait-for "there is weather info in the page"
80
81
 
81
82
  # visit github status page and save the status to ./status.json
82
- midscene --url https://www.githubstatus.com/ \\
83
+ midscene --url "https://www.githubstatus.com/" \\
83
84
  --query-output status.json \\
84
85
  --query '{name: string, status: string}[], service status of github page'
85
86
 
86
87
  Examples with Chinese Prompts
87
88
  # headed 模式(即可见浏览器)访问 baidu.com 并搜索“天气”
88
- midscene --headed --url https://www.baidu.com --action "在搜索框输入 '天气', 敲回车" --sleep 3000
89
+ midscene --headed --url "https://www.baidu.com" --action "在搜索框输入 '天气', 敲回车" --wait-for 界面上出现了天气信息
89
90
 
90
91
  # 访问 Github 状态页面并将状态保存到 ./status.json
91
- midscene --url https://www.githubstatus.com/ \\
92
+ midscene --url "https://www.githubstatus.com/" \\
92
93
  --query-output status.json \\
93
94
  --query '{serviceName: string, status: string}[], github 页面的服务状态,返回服务名称'
94
95
  `);
package/dist/es/index.js CHANGED
@@ -9,7 +9,7 @@ var require_package = __commonJS({
9
9
  module.exports = {
10
10
  name: "@midscene/cli",
11
11
  description: "Cli for Midscene.js",
12
- version: "0.3.0",
12
+ version: "0.3.1-beta-20240821105917.0",
13
13
  "jsnext:source": "./src/index.ts",
14
14
  main: "./dist/lib/index.js",
15
15
  bin: {
@@ -29,7 +29,7 @@ var require_package = __commonJS({
29
29
  dependencies: {
30
30
  "@midscene/web": "workspace:*",
31
31
  "ora-classic": "5.4.2",
32
- puppeteer: "^22.8.0",
32
+ puppeteer: "23.0.2",
33
33
  yargs: "17.7.2"
34
34
  },
35
35
  devDependencies: {
@@ -129,7 +129,8 @@ var actionArgs = {
129
129
  assert: "assert",
130
130
  queryOutput: "query-output",
131
131
  query: "query",
132
- sleep: "sleep"
132
+ sleep: "sleep",
133
+ waitFor: "wait-for"
133
134
  };
134
135
  var defaultUA = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36";
135
136
  var welcome = "\nWelcome to @midscene/cli\n";
@@ -178,16 +179,19 @@ Promise.resolve(
178
179
  const page = await browser.newPage();
179
180
  await page.setUserAgent(ua);
180
181
  await page.setViewport(viewportConfig);
181
- updateSpin(stepString("launch", url));
182
- await page.goto(url);
183
- updateSpin(stepString("waitForNetworkIdle", url));
184
- await page.waitForNetworkIdle();
185
- printStep("launched", url);
186
- const agent = new PuppeteerAgent(page);
187
182
  let errorWhenRunning;
188
183
  let argName;
189
184
  let argValue;
185
+ let agent;
190
186
  try {
187
+ updateSpin(stepString("launch", url));
188
+ await page.goto(url);
189
+ updateSpin(stepString("waitForNetworkIdle", url));
190
+ await page.waitForNetworkIdle();
191
+ printStep("launched", url);
192
+ agent = new PuppeteerAgent(page, {
193
+ autoPrintReportMsg: false
194
+ });
191
195
  let index = 0;
192
196
  let outputPath;
193
197
  let actionStarted = false;
@@ -255,11 +259,23 @@ Promise.resolve(
255
259
  printStep(argName, String(argValue));
256
260
  break;
257
261
  }
262
+ case actionArgs.waitFor: {
263
+ const param = arg.value;
264
+ assert(param, "missing assertion for waitFor");
265
+ assert(typeof param === "string", "assertion must be a string");
266
+ await agent.aiWaitFor(param);
267
+ printStep(argName, String(argValue));
268
+ break;
269
+ }
258
270
  }
259
271
  index += 1;
260
272
  }
273
+ printStep("Done", `report: ${agent.reportFile}`);
261
274
  } catch (e) {
262
275
  printStep(`${argName} - Failed`, String(argValue));
276
+ if (agent == null ? void 0 : agent.reportFile) {
277
+ printStep("Report", agent.reportFile);
278
+ }
263
279
  printStep("Error", e.message);
264
280
  errorWhenRunning = e;
265
281
  }
package/dist/lib/help.js CHANGED
@@ -10,7 +10,7 @@ var require_package = __commonJS({
10
10
  module2.exports = {
11
11
  name: "@midscene/cli",
12
12
  description: "Cli for Midscene.js",
13
- version: "0.3.0",
13
+ version: "0.3.1-beta-20240821105917.0",
14
14
  "jsnext:source": "./src/index.ts",
15
15
  main: "./dist/lib/index.js",
16
16
  bin: {
@@ -30,7 +30,7 @@ var require_package = __commonJS({
30
30
  dependencies: {
31
31
  "@midscene/web": "workspace:*",
32
32
  "ora-classic": "5.4.2",
33
- puppeteer: "^22.8.0",
33
+ puppeteer: "23.0.2",
34
34
  yargs: "17.7.2"
35
35
  },
36
36
  devDependencies: {
@@ -73,23 +73,24 @@ if (process.argv.indexOf("--help") !== -1) {
73
73
  --assert <assert> Perform an assert, optional
74
74
  --query-output <path> Save the result of the query to a file, this must be put before --query, optional
75
75
  --query <query> Perform a query, optional
76
+ --wait-for <assertion> Wait for a condition to be met. The timeout is set to 15 seconds. optional
76
77
  --sleep <ms> Sleep for a number of milliseconds, optional
77
78
 
78
79
  Examples:
79
80
  # headed mode (i.e. visible browser) to visit bing.com and search for 'weather today'
80
- midscene --headed --url https://wwww.bing.com --action "type 'weather today' in search box, hit enter" --sleep 3000
81
+ midscene --headed --url "https://wwww.bing.com" --action "type 'weather today' in search box, hit enter" --wait-for "there is weather info in the page"
81
82
 
82
83
  # visit github status page and save the status to ./status.json
83
- midscene --url https://www.githubstatus.com/ \\
84
+ midscene --url "https://www.githubstatus.com/" \\
84
85
  --query-output status.json \\
85
86
  --query '{name: string, status: string}[], service status of github page'
86
87
 
87
88
  Examples with Chinese Prompts
88
89
  # headed 模式(即可见浏览器)访问 baidu.com 并搜索“天气”
89
- midscene --headed --url https://www.baidu.com --action "在搜索框输入 '天气', 敲回车" --sleep 3000
90
+ midscene --headed --url "https://www.baidu.com" --action "在搜索框输入 '天气', 敲回车" --wait-for 界面上出现了天气信息
90
91
 
91
92
  # 访问 Github 状态页面并将状态保存到 ./status.json
92
- midscene --url https://www.githubstatus.com/ \\
93
+ midscene --url "https://www.githubstatus.com/" \\
93
94
  --query-output status.json \\
94
95
  --query '{serviceName: string, status: string}[], github 页面的服务状态,返回服务名称'
95
96
  `);
package/dist/lib/index.js CHANGED
@@ -31,7 +31,7 @@ var require_package = __commonJS({
31
31
  module2.exports = {
32
32
  name: "@midscene/cli",
33
33
  description: "Cli for Midscene.js",
34
- version: "0.3.0",
34
+ version: "0.3.1-beta-20240821105917.0",
35
35
  "jsnext:source": "./src/index.ts",
36
36
  main: "./dist/lib/index.js",
37
37
  bin: {
@@ -51,7 +51,7 @@ var require_package = __commonJS({
51
51
  dependencies: {
52
52
  "@midscene/web": "workspace:*",
53
53
  "ora-classic": "5.4.2",
54
- puppeteer: "^22.8.0",
54
+ puppeteer: "23.0.2",
55
55
  yargs: "17.7.2"
56
56
  },
57
57
  devDependencies: {
@@ -151,7 +151,8 @@ var actionArgs = {
151
151
  assert: "assert",
152
152
  queryOutput: "query-output",
153
153
  query: "query",
154
- sleep: "sleep"
154
+ sleep: "sleep",
155
+ waitFor: "wait-for"
155
156
  };
156
157
  var defaultUA = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/127.0.0.0 Safari/537.36";
157
158
  var welcome = "\nWelcome to @midscene/cli\n";
@@ -200,16 +201,19 @@ Promise.resolve(
200
201
  const page = await browser.newPage();
201
202
  await page.setUserAgent(ua);
202
203
  await page.setViewport(viewportConfig);
203
- updateSpin(stepString("launch", url));
204
- await page.goto(url);
205
- updateSpin(stepString("waitForNetworkIdle", url));
206
- await page.waitForNetworkIdle();
207
- printStep("launched", url);
208
- const agent = new import_web.PuppeteerAgent(page);
209
204
  let errorWhenRunning;
210
205
  let argName;
211
206
  let argValue;
207
+ let agent;
212
208
  try {
209
+ updateSpin(stepString("launch", url));
210
+ await page.goto(url);
211
+ updateSpin(stepString("waitForNetworkIdle", url));
212
+ await page.waitForNetworkIdle();
213
+ printStep("launched", url);
214
+ agent = new import_web.PuppeteerAgent(page, {
215
+ autoPrintReportMsg: false
216
+ });
213
217
  let index = 0;
214
218
  let outputPath;
215
219
  let actionStarted = false;
@@ -277,11 +281,23 @@ Promise.resolve(
277
281
  printStep(argName, String(argValue));
278
282
  break;
279
283
  }
284
+ case actionArgs.waitFor: {
285
+ const param = arg.value;
286
+ (0, import_node_assert.default)(param, "missing assertion for waitFor");
287
+ (0, import_node_assert.default)(typeof param === "string", "assertion must be a string");
288
+ await agent.aiWaitFor(param);
289
+ printStep(argName, String(argValue));
290
+ break;
291
+ }
280
292
  }
281
293
  index += 1;
282
294
  }
295
+ printStep("Done", `report: ${agent.reportFile}`);
283
296
  } catch (e) {
284
297
  printStep(`${argName} - Failed`, String(argValue));
298
+ if (agent == null ? void 0 : agent.reportFile) {
299
+ printStep("Report", agent.reportFile);
300
+ }
285
301
  printStep("Error", e.message);
286
302
  errorWhenRunning = e;
287
303
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@midscene/cli",
3
3
  "description": "Cli for Midscene.js",
4
- "version": "0.3.0",
4
+ "version": "0.3.1-beta-20240821105917.0",
5
5
  "jsnext:source": "./src/index.ts",
6
6
  "main": "./dist/lib/index.js",
7
7
  "bin": {
@@ -13,9 +13,9 @@
13
13
  ],
14
14
  "dependencies": {
15
15
  "ora-classic": "5.4.2",
16
- "puppeteer": "^22.8.0",
16
+ "puppeteer": "23.0.2",
17
17
  "yargs": "17.7.2",
18
- "@midscene/web": "0.3.0"
18
+ "@midscene/web": "0.3.1-beta-20240821105917.0"
19
19
  },
20
20
  "devDependencies": {
21
21
  "@modern-js/module-tools": "^2.56.1",