chore: optimize code style (#77)

This commit is contained in:
Zhou xiao 2024-08-28 14:59:25 +08:00 committed by GitHub
parent 952d13e8b0
commit e071adfa70
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 8 additions and 18 deletions

16
.vscode/settings.json vendored
View File

@ -3,20 +3,6 @@
"source.organizeImports.biome": "explicit"
},
"editor.defaultFormatter": "biomejs.biome",
"eslint.validate": [
"javascript",
"javascriptreact",
"typescript",
"typescriptreact",
"vue",
"html"
],
"eslint.nodePath": "node_modules",
"eslint.trace.server": "verbose",
"eslint.workingDirectories": [
{
"mode": "auto"
}
],
"editor.formatOnSave": true,
"editor.formatOnSaveMode": "modifications"
}

View File

@ -37,6 +37,7 @@ export default defineConfig({
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
deviceScaleFactor: process.platform === 'darwin' ? 2 : 1, // Device scaling factor
},
/* Configure projects for major browsers */

View File

@ -1,5 +1,7 @@
import type { Page as PlaywrightPage } from 'playwright';
import type { KeyInput, Page as PuppeteerPage } from 'puppeteer';
export type WebPage = PlaywrightPage | PuppeteerPage;
export type WebPage = (PlaywrightPage | PuppeteerPage) & {
evaluate<R, Arg>(pageFunction: PageFunction<Arg, R>, arg?: Arg): Promise<R>;
};
export type WebKeyInput = KeyInput;

View File

@ -52,7 +52,7 @@ export class PageTaskExecutor {
}
private async recordScreenshot(timing: ExecutionRecorderItem['timing']) {
const file = getTmpFile('jpeg');
const file = getTmpFile('png');
await this.page.screenshot({
...commonScreenshotParam,
path: file,

View File

@ -22,6 +22,7 @@ export async function parseContextFromWebPage(
const url = page.url();
const file = getTmpFile('jpeg');
await page.screenshot({ path: file, type: 'jpeg', quality: 75 });
const screenshotBuffer = readFileSync(file);
const screenshotBase64 = base64Encoded(file);
@ -51,7 +52,7 @@ export async function getElementInfosFromPage(page: WebPage) {
const elementInfosScriptContent = readFileSync(scriptPath, 'utf-8');
const extraReturnLogic = `${elementInfosScriptContent}midscene_element_inspector.extractTextWithPosition()`;
const captureElementSnapshot = await (page as any).evaluate(extraReturnLogic);
const captureElementSnapshot = await page.evaluate(extraReturnLogic);
return captureElementSnapshot as Array<ElementInfo>;
}