midscene/packages/web-integration/tests/unit-test/client-extractor.test.ts
yuyutaotao 9d5f2fbcac
feat(web-extract): extract web content as a tree (#337)
* feat: extract web content as a tree

* chore: update test data

* chore: update test data

* feat: update answer of evaluation

* chore: update test cases

* chore: remove focusing on cases

* fix: ci

* fix: put rect in html tree

* fix: CI

* fix: AI test

* fix: lint

* fix: CI

* fix: static-page compatibility

* fix: CI

* fix: map by markerId

* fix: llm planning prompt

* chore: update hash length

* chore: ignore writing dump file

* fix: lint

* fix: ci snapshot

* chore: snapshot tree in web extractor

* chore: export tree utils in core

* chore: export tree utils in core

* fix: CI

* fix: update test case and evaluation

* chore: remove unused file

* refactor(extract): modify dependencies (#358)

* refactor(extract): modify dependencies

* chore: modify files config

* chore: add indexId as key for map

---------

Co-authored-by: Zhou Xiao <zhouxiao.shaw@bytedance.com>
2025-02-07 14:55:52 +08:00

69 lines
1.6 KiB
TypeScript

import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import { describe, expect, it } from 'vitest';
import { AppiumPage } from '@/appium';
const iosXmlPath = join(
__dirname,
'./fixtures/client-extractor/ios-setting.xml',
);
const androidXmlPath = join(
__dirname,
'./fixtures/client-extractor/android-setting.xml',
);
class Browser {
xmlPath: string;
windowSize: { width: number; height: number };
constructor(xmlPath: string, windowSize: { width: number; height: number }) {
this.xmlPath = xmlPath;
this.windowSize = windowSize;
}
getWindowSize() {
return Promise.resolve(this.windowSize);
}
getPageSource() {
return Promise.resolve(readFileSync(this.xmlPath, 'utf-8'));
}
}
class AndroidBrowser {
getWindowSize() {
return Promise.resolve({
width: 430,
height: 932,
});
}
getPageSource() {
return Promise.resolve(readFileSync(androidXmlPath, 'utf-8'));
}
}
describe(
'extractor',
() => {
it('ios', async () => {
const browser = new Browser(iosXmlPath, {
width: 430,
height: 932,
}) as unknown as import('webdriverio').Browser;
const page = new AppiumPage(browser);
const infos = await page.getElementsInfo();
expect(infos).toMatchSnapshot();
});
it('android', async () => {
const browser = new Browser(androidXmlPath, {
width: 1080,
height: 2400,
}) as unknown as import('webdriverio').Browser;
const page = new AppiumPage(browser);
const infos = await page.getElementsInfo();
expect(infos).toMatchSnapshot();
});
},
{
timeout: 90 * 1000,
},
);