Skip to content

Commit

Permalink
fix: static-page compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyutaotao committed Feb 5, 2025
1 parent c46dbf3 commit 05d0dc3
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 174 deletions.
6 changes: 3 additions & 3 deletions packages/midscene/src/ai-model/prompt/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ export async function descriptionOfTree<
const indentStr = ' '.repeat(indent);

let children = '';
for (let i = 0; i < node.children.length; i++) {
for (let i = 0; i < (node.children || []).length; i++) {
const childContent = buildContentTree(node.children[i], indent + 1);
if (childContent) {
children += `\n${childContent}`;
Expand Down Expand Up @@ -405,11 +405,11 @@ export async function describeUserPage<
const idElementMap: Record<string, ElementType> = {};
const flatElements: ElementType[] = [];
function dfsTree(node: ElementTreeNode<ElementType>) {
if (node.node) {
if (node?.node) {
idElementMap[node.node.id] = node.node;
flatElements.push(node.node);
}
for (let i = 0; i < node.children.length; i++) {
for (let i = 0; i < (node.children || []).length; i++) {
dfsTree(node.children[i]);
}
}
Expand Down
5 changes: 5 additions & 0 deletions packages/midscene/tests/ai/connectivity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ import dotenv from 'dotenv';
import { getFixture } from 'tests/utils';
import { beforeAll, describe, expect, it, vi } from 'vitest';

dotenv.config({
debug: true,
override: true,
});

vi.setConfig({
testTimeout: 20 * 1000,
});
Expand Down
7 changes: 6 additions & 1 deletion packages/midscene/tests/ai/evaluate/assertion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@ import {
repeatFile,
} from './test-suite/util';
import 'dotenv/config';
import { repeatTime } from '../util';
import dotenv from 'dotenv';

dotenv.config({
debug: true,
override: true,
});

const testSources = [
'online_order',
Expand Down
169 changes: 0 additions & 169 deletions packages/midscene/tests/ai/evaluate/computer.test.ts

This file was deleted.

6 changes: 6 additions & 0 deletions packages/midscene/tests/ai/evaluate/inspect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@ import {
runTestCases,
} from './test-suite/util';
import 'dotenv/config';
import dotenv from 'dotenv';
import { repeatTime } from '../util';

dotenv.config({
debug: true,
override: true,
});

const relocateAfterPlanning = false;
const failCaseThreshold = process.env.CI ? 1 : 0;
const testSources = [
Expand Down
2 changes: 2 additions & 0 deletions packages/midscene/vitest.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import { version } from './package.json';
*/
dotenv.config({
path: path.join(__dirname, '../../.env'),
override: true,
debug: true,
});

const enableAiTest = Boolean(process.env.AITEST);
Expand Down
15 changes: 14 additions & 1 deletion packages/web-integration/src/playground/static-page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,20 @@ export default class StaticPage implements AbstractPage {
private uiContext: WebUIContext;

constructor(uiContext: WebUIContext) {
this.uiContext = uiContext;
if (uiContext.tree) {
this.uiContext = uiContext;
} else {
const contents = uiContext.content;
this.uiContext = Object.assign(uiContext, {
tree: {
node: null,
children: contents.map((content) => ({

Check failure on line 27 in packages/web-integration/src/playground/static-page.ts

View workflow job for this annotation

GitHub Actions / main (18.19.0)

tests/unit-test/web-extractor.test.ts > extractor > static page with fixed context

TypeError: Cannot read properties of undefined (reading 'map') ❯ new StaticPage src/playground/static-page.ts:27:30 ❯ tests/unit-test/web-extractor.test.ts:186:20

Check failure on line 27 in packages/web-integration/src/playground/static-page.ts

View workflow job for this annotation

GitHub Actions / release (18.19.0)

tests/unit-test/web-extractor.test.ts > extractor > static page with fixed context

TypeError: Cannot read properties of undefined (reading 'map') ❯ new StaticPage src/playground/static-page.ts:27:30 ❯ tests/unit-test/web-extractor.test.ts:186:20
node: content,
children: [],
})),
},
});
}
}

async getElementsInfo() {
Expand Down

0 comments on commit 05d0dc3

Please sign in to comment.