Skip to content

Commit

Permalink
chore: optimize unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
zhoushaw committed Aug 22, 2024
1 parent e4494a7 commit c5c0ed2
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 12 deletions.
4 changes: 3 additions & 1 deletion packages/web-integration/src/debug/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export async function generateExtractData(
disableSnapshot: boolean;
},
) {
const buffer = await page.screenshot();
const buffer = await page.screenshot({
encoding: 'base64',
});
const inputImgBase64 = buffer.toString('base64');

const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,24 @@ exports[`extractor > basic 1`] = `
},
"content": "this_is_a_textarea",
},
{
"attributes": {
"nodeType": "TEXT Node",
},
"content": "English",
},
{
"attributes": {
"nodeType": "TEXT Node",
},
"content": "中文",
},
{
"attributes": {
"nodeType": "TEXT Node",
},
"content": "Tiếng Việt",
},
{
"attributes": {
"nodeType": "TEXT Node",
Expand Down
7 changes: 3 additions & 4 deletions packages/web-integration/tests/unit-test/extractor.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import path, { join } from 'node:path';
import { parseContextFromWebPage } from '@/common/utils';
import { generateTestData } from 'tests/ai/e2e/tool';
import { generateExtractData } from '@/debug';
import { describe, expect, it } from 'vitest';
import { launchPage } from '../ai/puppeteer/utils';

Expand All @@ -11,11 +11,10 @@ describe(
it('basic', async () => {
const { page, reset } = await launchPage(`file://${pagePath}`);

const { content, screenshotBase64 } = await parseContextFromWebPage(page);
await generateTestData(
const { content } = await parseContextFromWebPage(page);
await generateExtractData(
page,
path.join(__dirname, 'fixtures/extractor'),
screenshotBase64,
{
disableInputImage: false,
disableOutputImage: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,21 +96,44 @@ <h3>Form</h3>
<img src="https://lf3-static.bytednsdoc.com/obj/eden-cn/vhaeh7vhabf/midscene.png" width="2" height="2"
alt="small_img" />
</div>

<!-- Global popup to test invisible -->
<div style="position: absolute; top: 0px; left: 500px; width: 100%;">
<div>
<div style="left: 59px; top: 46px;">
<ul >
<li><span>English</span></li>
<li><span>中文</span></li>
<li><span>Tiếng Việt</span>
</li>
</ul>
</div>
</div>
</div>


<!-- from ebay -->
<div id="gh-ac-box2" _midscene_retrieve_task_id="7de6fc64a5"><label for="gh-ac" class="gh-ar-hdn">输入搜索关键词</label><input
type="text" class="gh-tb ui-autocomplete-input" aria-autocomplete="list" aria-expanded="false" size="50"
maxlength="300" aria-label="搜索任何物品" placeholder="搜索任何物品" id="gh-ac" name="_nkw" autocapitalize="off"
autocorrect="off" spellcheck="false" autocomplete="off" aria-haspopup="true" role="combobox" aria-owns="ui-id-1"
_midscene_retrieve_task_id="36bc72f23a"><span role="status" aria-live="polite"
<div id="gh-ac-box2" _midscene_retrieve_task_id="7de6fc64a5"><label for="gh-ac"
class="gh-ar-hdn">输入搜索关键词</label><input type="text" class="gh-tb ui-autocomplete-input" aria-autocomplete="list"
aria-expanded="false" size="50" maxlength="300" aria-label="搜索任何物品" placeholder="搜索任何物品" id="gh-ac" name="_nkw"
autocapitalize="off" autocorrect="off" spellcheck="false" autocomplete="off" aria-haspopup="true" role="combobox"
aria-owns="ui-id-1" _midscene_retrieve_task_id="36bc72f23a"><span role="status" aria-live="polite"
class="ui-helper-hidden-accessible"></span><input style="display:none">
<script> if (document.getElementById('gh-ac').value.length !== 0) { document.getElementById('gh-ac-box').classList.add('gh-ac-box-focus'); document.getElementById('gh').classList.add('gh-sch-focus'); } </script>
<script>
if (document.getElementById('gh-ac').value.length !== 0) {
document.getElementById('gh-ac-box').classList.add('gh-ac-box-focus');
document.getElementById('gh').classList.add('gh-sch-focus');
}
</script>
<svg aria-hidden="true" class="icon icon--search gh-search__icon" focusable="false" height="16" width="16">
<use xlink:href="#gh-icon-search-evo"></use>
</svg>
</div>


<script>
var input = document.getElementById('J_input');
var keyRecord = document.getElementById('J_keyRecord');
var keyRecord = document.getElementById('J_keyRecord');
input.addEventListener('keyup', function (e) {
keyRecord.innerHTML += '\n' + e.key;
});
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit c5c0ed2

Please sign in to comment.