Skip to content

Commit eba5012

Browse files
committed
fix: screenshot output in web extractor
1 parent cbbcb71 commit eba5012

File tree

3 files changed

+21
-16
lines changed

3 files changed

+21
-16
lines changed

packages/midscene/src/ai-model/service-caller/index.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import {
1919
MIDSCENE_API_TYPE,
2020
MIDSCENE_AZURE_OPENAI_INIT_CONFIG_JSON,
2121
MIDSCENE_AZURE_OPENAI_SCOPE,
22-
MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG,
2322
MIDSCENE_DEBUG_AI_PROFILE,
2423
MIDSCENE_LANGSMITH_DEBUG,
2524
MIDSCENE_MODEL_NAME,
@@ -31,7 +30,6 @@ import {
3130
OPENAI_BASE_URL,
3231
OPENAI_MAX_TOKENS,
3332
OPENAI_USE_AZURE,
34-
allAIConfig,
3533
getAIConfig,
3634
getAIConfigInJson,
3735
} from '../../env';
Loading

packages/web-integration/tests/unit-test/web-extractor.test.ts

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import { parseContextFromWebPage } from '@/common/utils';
33
import StaticPage from '@/playground/static-page';
44
import type { WebElementInfo } from '@/web-element';
55
import { traverseTree } from '@midscene/shared/extractor';
6-
import { imageInfoOfBase64 } from '@midscene/shared/img';
6+
import {
7+
compositeElementInfoImg,
8+
imageInfoOfBase64,
9+
saveBase64Image,
10+
} from '@midscene/shared/img';
711
import { createServer } from 'http-server';
812
import { beforeAll, describe, expect, it } from 'vitest';
913
import { launchPage } from '../ai/web/puppeteer/utils';
@@ -39,19 +43,22 @@ describe(
3943
},
4044
});
4145

42-
const { content, tree } = await parseContextFromWebPage(page);
43-
// TODO
44-
// await generateExtractData(
45-
// page,
46-
// path.join(__dirname, 'fixtures/web-extractor'),
47-
// {
48-
// disableInputImage: false,
49-
// disableOutputImage: false,
50-
// disableOutputWithoutTextImg: true,
51-
// disableResizeOutputImg: true,
52-
// disableSnapshot: true,
53-
// },
54-
// );
46+
const { content, tree, screenshotBase64 } =
47+
await parseContextFromWebPage(page);
48+
49+
const markedImg = await compositeElementInfoImg({
50+
inputImgBase64: await page.screenshotBase64(),
51+
elementsPositionInfo: content,
52+
});
53+
54+
await saveBase64Image({
55+
base64Data: screenshotBase64,
56+
outputPath: join(pageDir, 'input.png'),
57+
});
58+
await saveBase64Image({
59+
base64Data: markedImg,
60+
outputPath: join(pageDir, 'output.png'),
61+
});
5562

5663
const list = content.map((item) => {
5764
return {

0 commit comments

Comments
 (0)