Skip to content

Commit

Permalink
feat(web-extract): extract some <div />s as container (#80)
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyutaotao authored Aug 31, 2024
1 parent 3769a55 commit 704a0b8
Show file tree
Hide file tree
Showing 49 changed files with 2,166 additions and 1,092 deletions.
15 changes: 14 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,20 @@ jobs:
uses: actions/setup-node@v4
with:
node-version: '18'
cache: 'pnpm'

- name: Get pnpm store directory
id: pnpm-cache
shell: bash
run: |
echo "STORE_PATH=$(pnpm store path)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3
name: Setup pnpm cache
with:
path: ${{ steps.pnpm-cache.outputs.STORE_PATH }}
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install dependencies
run: pnpm install --frozen-lockfile
Expand Down
4 changes: 4 additions & 0 deletions apps/site/docs/en/docs/usage/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ expect(onesieItem.price).toBe(7.99);

When considering the time required for the AI service, `.aiWaitFor` may not be very efficient. Using a simple `sleep` method might be a useful alternative to `waitFor`.

```typescript
await mid.aiWaitFor("there is at least one headphone item on page");
```

## Debug Config (Optional)

### Print the AI profiling
Expand Down
5 changes: 5 additions & 0 deletions apps/site/docs/zh/docs/usage/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ expect(onesieItem.price).toBe(7.99);

考虑到 AI 服务的时间消耗,`.aiWaitFor` 并不是一个特别高效的方法。使用一个普通的 `sleep` 可能是替代 `waitFor` 的另一种方式。

```typescript
await mid.aiWaitFor("界面上至少有一个耳机的信息");
```


## 调试配置(可选)

### 打印 AI 性能信息
Expand Down
1 change: 1 addition & 0 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
"**/midscene_run",
".nx",
"**/dist",
"**/test-data/**",
"dist",
"**/doc_build",
"*-dump.json",
Expand Down
1 change: 1 addition & 0 deletions packages/midscene/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface Size {
export type Rect = Point & Size;

enum NodeType {
CONTAINER = 'CONTAINER Node',
FORM_ITEM = 'FORM_ITEM Node',
BUTTON = 'BUTTON Node',
IMG = 'IMG Node',
Expand Down
10 changes: 9 additions & 1 deletion packages/midscene/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,15 @@ export function writeDumpReport(
const reportPath = join(getLogDirByType('report'), `${fileName}.html`);
const tpl = readFileSync(reportTplPath, 'utf-8');
let reportContent: string;
if (typeof dumpData === 'string') {
if (
(Array.isArray(dumpData) && dumpData.length === 0) ||
typeof dumpData === 'undefined'
) {
reportContent = tpl.replace(
'{{dump}}',
'<script type="midscene_web_dump" type="application/json"></script>',
);
} else if (typeof dumpData === 'string') {
reportContent = tpl.replace(
'{{dump}}',
`<script type="midscene_web_dump" type="application/json">${dumpData}</script>`,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,6 @@ exports[`automation - planning input - openAI > input value 1`] = `
"thought": undefined,
"type": "Locate",
},
{
"param": null,
"thought": undefined,
"type": "Tap",
},
{
"param": {
"value": "learning english",
Expand Down Expand Up @@ -83,6 +78,18 @@ exports[`automation - planning input - openAI > input value Add, delete, correct
"thought": undefined,
"type": "Locate",
},
{
"param": null,
"thought": undefined,
"type": "Tap",
},
{
"param": {
"value": "",
},
"thought": undefined,
"type": "Input",
},
{
"param": {
"value": "Learn skiing",
Expand All @@ -102,11 +109,6 @@ exports[`automation - planning input - openAI > input value Add, delete, correct
"thought": undefined,
"type": "Locate",
},
{
"param": null,
"thought": undefined,
"type": "Tap",
},
{
"param": {
"value": "Learn ",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"elements": [
{
"id": "f775c69cb4",
"indexId": "4",
"indexId": "5",
},
],
"error": [],
Expand All @@ -33,11 +33,11 @@
"elements": [
{
"id": "14103376fb",
"indexId": "25",
"indexId": "24",
},
{
"id": "0250e12e67",
"indexId": "31",
"indexId": "30",
},
],
"error": [],
Expand All @@ -47,11 +47,11 @@
"elements": [
{
"id": "fadfa10182",
"indexId": "26",
"indexId": "25",
},
{
"id": "001617dbf8",
"indexId": "32",
"indexId": "31",
},
],
"error": [],
Expand All @@ -61,7 +61,7 @@
"elements": [
{
"id": "cad3004a2d",
"indexId": "33",
"indexId": "32",
},
],
"error": [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
{
"elements": [
{
"id": "7b0f4c3c94",
"indexId": "11",
"id": "e477ad490a",
"indexId": "10",
},
],
"error": [],
Expand All @@ -23,7 +23,7 @@
"elements": [
{
"id": "7ccd467339",
"indexId": "13",
"indexId": "12",
},
],
"error": [],
Expand All @@ -33,7 +33,7 @@
"elements": [
{
"id": "eb987bf616",
"indexId": "14",
"indexId": "13",
},
],
"error": [],
Expand All @@ -43,7 +43,7 @@
"elements": [
{
"id": "284ba7f2b3",
"indexId": "20",
"indexId": "19",
},
],
"error": [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { readFileSync } from 'node:fs';
import path from 'node:path';
import { AiInspectElement } from '@/ai-model';
import { expect, test } from 'vitest';
Expand Down
Loading

0 comments on commit 704a0b8

Please sign in to comment.