2025-04-01 10:41:31 +08:00
|
|
|
import { distance } from '@/ai-model/prompt/util';
|
2025-03-24 09:50:27 +08:00
|
|
|
import Insight from '@/insight';
|
|
|
|
import { sleep } from '@/utils';
|
2025-04-24 22:54:52 +08:00
|
|
|
import { vlLocateMode } from '@midscene/shared/env';
|
2025-03-24 09:50:27 +08:00
|
|
|
import { getContextFromFixture } from 'tests/evaluation';
|
2025-03-25 10:04:03 +08:00
|
|
|
import { describe, expect, test, vi } from 'vitest';
|
2025-03-24 09:50:27 +08:00
|
|
|
|
|
|
|
vi.setConfig({
|
|
|
|
testTimeout: 60 * 1000,
|
|
|
|
});
|
|
|
|
|
2025-03-25 10:04:03 +08:00
|
|
|
const vlMode = vlLocateMode();
|
2025-03-24 09:50:27 +08:00
|
|
|
|
2025-04-10 16:54:21 +08:00
|
|
|
describe.skipIf(!vlMode)('insight locate with deep think', () => {
|
2025-03-25 10:04:03 +08:00
|
|
|
test('insight locate with search area', async () => {
|
|
|
|
const { context } = await getContextFromFixture('taobao');
|
2025-03-24 09:50:27 +08:00
|
|
|
|
2025-03-25 10:04:03 +08:00
|
|
|
const insight = new Insight(context);
|
|
|
|
const { element } = await insight.locate({
|
|
|
|
prompt: '购物车 icon',
|
2025-04-10 16:54:21 +08:00
|
|
|
deepThink: true,
|
2025-03-25 10:04:03 +08:00
|
|
|
});
|
|
|
|
expect(element).toBeDefined();
|
|
|
|
|
|
|
|
await sleep(3000);
|
|
|
|
});
|
2025-03-24 09:50:27 +08:00
|
|
|
|
2025-03-25 10:04:03 +08:00
|
|
|
test('insight locate with search area and think twice', async () => {
|
|
|
|
const { context } = await getContextFromFixture('taobao');
|
2025-03-24 09:50:27 +08:00
|
|
|
|
2025-03-25 10:04:03 +08:00
|
|
|
const insight = new Insight(context);
|
2025-04-01 10:41:31 +08:00
|
|
|
const { element, rect } = await insight.locate({
|
2025-03-25 10:04:03 +08:00
|
|
|
prompt: '顶部购物车 icon',
|
|
|
|
deepThink: true,
|
|
|
|
});
|
|
|
|
expect(element).toBeDefined();
|
2025-04-01 10:41:31 +08:00
|
|
|
expect(rect).toBeDefined();
|
|
|
|
expect(
|
|
|
|
distance(
|
|
|
|
{
|
|
|
|
x: element!.rect.left,
|
|
|
|
y: element!.rect.top,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
x: rect!.left,
|
|
|
|
y: rect!.top,
|
|
|
|
},
|
|
|
|
),
|
|
|
|
).toBeLessThan(100);
|
2025-03-25 10:04:03 +08:00
|
|
|
await sleep(3000);
|
2025-03-24 09:50:27 +08:00
|
|
|
});
|
|
|
|
});
|
2025-03-25 22:45:05 +08:00
|
|
|
|
|
|
|
vi.setConfig({
|
|
|
|
testTimeout: 60 * 1000,
|
|
|
|
});
|
|
|
|
|
2025-04-10 16:54:21 +08:00
|
|
|
test.skip('insight locate with search area', async () => {
|
|
|
|
const { context } = await getContextFromFixture('image-only');
|
2025-03-25 22:45:05 +08:00
|
|
|
|
2025-04-10 16:54:21 +08:00
|
|
|
const insight = new Insight(context);
|
|
|
|
const { element, rect } = await insight.locate({
|
|
|
|
prompt: '-',
|
|
|
|
deepThink: true,
|
|
|
|
});
|
|
|
|
console.log(element, rect);
|
|
|
|
await sleep(3000);
|
|
|
|
});
|