-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1cb6416
commit 8125e79
Showing
38 changed files
with
292 additions
and
391 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,10 +119,8 @@ | |
} | ||
} | ||
|
||
.context { | ||
pre { | ||
text-wrap: balance; | ||
} | ||
pre { | ||
text-wrap: balance; | ||
} | ||
|
||
.item-list-space-up { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { ExecutionDump, GroupedActionDump } from '@midscene/core'; | ||
import { groupedActionDumpFileExt, writeDumpFile } from '@midscene/core/utils'; | ||
import { PageTaskExecutor } from '../common/tasks'; | ||
import { WebPage } from '@/common/page'; | ||
|
||
export class PageAgent { | ||
page: WebPage; | ||
|
||
dumps: GroupedActionDump[]; | ||
|
||
constructor(page: WebPage) { | ||
this.page = page; | ||
this.dumps = []; | ||
} | ||
|
||
appendDump(groupName: string, execution: ExecutionDump) { | ||
let currentDump = this.dumps.find((dump) => dump.groupName === groupName); | ||
if (!currentDump) { | ||
currentDump = { | ||
groupName, | ||
executions: [], | ||
}; | ||
this.dumps.push(currentDump); | ||
} | ||
currentDump.executions.push(execution); | ||
} | ||
|
||
writeOutActionDumps() { | ||
writeDumpFile(`playwright-${process.pid}`, groupedActionDumpFileExt, JSON.stringify(this.dumps)); | ||
} | ||
|
||
async aiAction(taskPrompt: string, dumpGroupName = 'MidScene / Web', dumpCaseName = 'AI Action') { | ||
const actionAgent = new PageTaskExecutor(this.page, { taskName: dumpCaseName }); | ||
let error: Error | undefined; | ||
try { | ||
await actionAgent.action(taskPrompt); | ||
} catch (e: any) { | ||
error = e; | ||
} | ||
if (actionAgent.executionDump) { | ||
this.appendDump(dumpGroupName, actionAgent.executionDump); | ||
this.writeOutActionDumps(); | ||
} | ||
if (error) { | ||
// playwright cli won't print error cause, so we print it here | ||
console.error(error); | ||
throw new Error(error.message, { cause: error }); | ||
} | ||
} | ||
|
||
async aiQuery(demand: any, dumpGroupName = 'MidScene / Web', dumpCaseName = 'AI Query') { | ||
const actionAgent = new PageTaskExecutor(this.page, { taskName: dumpCaseName }); | ||
let error: Error | undefined; | ||
let result: any; | ||
try { | ||
result = await actionAgent.query(demand); | ||
} catch (e: any) { | ||
error = e; | ||
} | ||
if (actionAgent.executionDump) { | ||
this.appendDump(dumpGroupName, actionAgent.executionDump); | ||
this.writeOutActionDumps(); | ||
} | ||
if (error) { | ||
// playwright cli won't print error cause, so we print it here | ||
console.error(error); | ||
throw new Error(error.message, { cause: error }); | ||
} | ||
return result; | ||
} | ||
|
||
async ai(taskPrompt: string, type = 'action', dumpGroupName = 'MidScene / Web', dumpCaseName = 'AI') { | ||
if (type === 'action') { | ||
return this.aiAction(taskPrompt, dumpGroupName, dumpCaseName); | ||
} else if (type === 'query') { | ||
return this.aiQuery(taskPrompt, dumpGroupName, dumpCaseName); | ||
} | ||
throw new Error(`Unknown or Unsupported task type: ${type}, only support 'action' or 'query'`); | ||
} | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import type { Page as PlaywrightPage } from 'playwright'; | ||
import type { Page as PuppeteerPage, KeyInput } from 'puppeteer'; | ||
|
||
export type WebPage = PlaywrightPage | PuppeteerPage; | ||
export type WebKeyInput = KeyInput; |
Oops, something went wrong.