midscene/packages/core/tests/ai/insight/insight.test.ts
Leyang ca644d8914
feat(core): allow custom midscene_run dir (#631)
* feat(core): support custom midscene_run dir

* feat(report): add search functionality to PlaywrightCaseSelector component

* refactor(shared): simplify base directory resolution and remove unused environment variable

* feat(shared): integrate shared environment variables across multiple packages

* refactor(shared): update base directory resolution to use dynamic midscene_run directory

* fix(puppeteer): increase screenshot timeout from 3s to 10s for improved reliability
2025-04-24 22:54:52 +08:00

69 lines
1.7 KiB
TypeScript

import { distance } from '@/ai-model/prompt/util';
import Insight from '@/insight';
import { sleep } from '@/utils';
import { vlLocateMode } from '@midscene/shared/env';
import { getContextFromFixture } from 'tests/evaluation';
import { describe, expect, test, vi } from 'vitest';
vi.setConfig({
testTimeout: 60 * 1000,
});
const vlMode = vlLocateMode();
describe.skipIf(!vlMode)('insight locate with deep think', () => {
test('insight locate with search area', async () => {
const { context } = await getContextFromFixture('taobao');
const insight = new Insight(context);
const { element } = await insight.locate({
prompt: '购物车 icon',
deepThink: true,
});
expect(element).toBeDefined();
await sleep(3000);
});
test('insight locate with search area and think twice', async () => {
const { context } = await getContextFromFixture('taobao');
const insight = new Insight(context);
const { element, rect } = await insight.locate({
prompt: '顶部购物车 icon',
deepThink: true,
});
expect(element).toBeDefined();
expect(rect).toBeDefined();
expect(
distance(
{
x: element!.rect.left,
y: element!.rect.top,
},
{
x: rect!.left,
y: rect!.top,
},
),
).toBeLessThan(100);
await sleep(3000);
});
});
vi.setConfig({
testTimeout: 60 * 1000,
});
test.skip('insight locate with search area', async () => {
const { context } = await getContextFromFixture('image-only');
const insight = new Insight(context);
const { element, rect } = await insight.locate({
prompt: '-',
deepThink: true,
});
console.log(element, rect);
await sleep(3000);
});