Skip to content

Commit

Permalink
fix: screenshot output in web extractor
Browse files Browse the repository at this point in the history
  • Loading branch information
yuyutaotao committed Feb 10, 2025
1 parent cbbcb71 commit eba5012
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
2 changes: 0 additions & 2 deletions packages/midscene/src/ai-model/service-caller/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import {
MIDSCENE_API_TYPE,
MIDSCENE_AZURE_OPENAI_INIT_CONFIG_JSON,
MIDSCENE_AZURE_OPENAI_SCOPE,
MIDSCENE_DANGEROUSLY_PRINT_ALL_CONFIG,
MIDSCENE_DEBUG_AI_PROFILE,
MIDSCENE_LANGSMITH_DEBUG,
MIDSCENE_MODEL_NAME,
Expand All @@ -31,7 +30,6 @@ import {
OPENAI_BASE_URL,
OPENAI_MAX_TOKENS,
OPENAI_USE_AZURE,
allAIConfig,
getAIConfig,
getAIConfigInJson,
} from '../../env';
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
35 changes: 21 additions & 14 deletions packages/web-integration/tests/unit-test/web-extractor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import { parseContextFromWebPage } from '@/common/utils';
import StaticPage from '@/playground/static-page';
import type { WebElementInfo } from '@/web-element';
import { traverseTree } from '@midscene/shared/extractor';
import { imageInfoOfBase64 } from '@midscene/shared/img';
import {
compositeElementInfoImg,
imageInfoOfBase64,
saveBase64Image,
} from '@midscene/shared/img';
import { createServer } from 'http-server';
import { beforeAll, describe, expect, it } from 'vitest';
import { launchPage } from '../ai/web/puppeteer/utils';
Expand Down Expand Up @@ -39,19 +43,22 @@ describe(
},
});

const { content, tree } = await parseContextFromWebPage(page);
// TODO
// await generateExtractData(
// page,
// path.join(__dirname, 'fixtures/web-extractor'),
// {
// disableInputImage: false,
// disableOutputImage: false,
// disableOutputWithoutTextImg: true,
// disableResizeOutputImg: true,
// disableSnapshot: true,
// },
// );
const { content, tree, screenshotBase64 } =
await parseContextFromWebPage(page);

const markedImg = await compositeElementInfoImg({
inputImgBase64: await page.screenshotBase64(),
elementsPositionInfo: content,
});

await saveBase64Image({
base64Data: screenshotBase64,
outputPath: join(pageDir, 'input.png'),
});
await saveBase64Image({
base64Data: markedImg,
outputPath: join(pageDir, 'output.png'),
});

const list = content.map((item) => {
return {
Expand Down

0 comments on commit eba5012

Please sign in to comment.