-
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
8125e79
commit 7787a4f
Showing
5 changed files
with
28 additions
and
35 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,4 @@ | ||
export { PlaywrightAiFixture } from './playwright'; | ||
export type { PlayWrightAiFixtureType } from './playwright'; | ||
|
||
export { PuppeteerAgent } from './puppeteer'; |
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 { PageAgent } from '@/common/agent'; | ||
|
||
const PuppeteerAgent = PageAgent; | ||
|
||
export { PuppeteerAgent }; |
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 |
---|---|---|
@@ -1,33 +1,23 @@ | ||
import puppeteer, { Viewport } from 'puppeteer'; | ||
import { it, describe, expect, vi } from 'vitest'; | ||
import { sleep } from '@midscene/core/utils'; | ||
import { launchPage } from './utils'; | ||
import { PuppeteerAgent } from '@/puppeteer'; | ||
|
||
const launchPage = async ( | ||
url: string, | ||
opt?: { | ||
viewport?: Viewport; | ||
}, | ||
) => { | ||
const browser = await puppeteer.launch(); | ||
vi.setConfig({ | ||
testTimeout: 60 * 1000, | ||
}); | ||
|
||
const page = (await browser.pages())[0]; | ||
const viewportConfig = { | ||
width: opt?.viewport?.pixelWidth || 1920, | ||
height: opt?.viewport?.pixelHeight || 1080, | ||
deviceScaleFactor: opt?.viewport?.dpr || 1, | ||
}; | ||
await page.setViewport(viewportConfig); | ||
await Promise.all([ | ||
page.waitForNavigation({ | ||
timeout: 20 * 1000, | ||
waitUntil: 'networkidle0', | ||
}), | ||
(async () => { | ||
const response = await page.goto(url); | ||
if (response?.status) { | ||
assert(response.status() <= 399, `Page load failed: ${response.status()}`); | ||
} | ||
})(), | ||
]); | ||
await sleep(2 * 1000); | ||
describe('puppeteer integration', () => { | ||
it('basic launch', async () => { | ||
const page = await launchPage('https://www.bing.com'); | ||
|
||
return browser; | ||
}; | ||
const agent = new PuppeteerAgent(page); | ||
|
||
await agent.aiAction('type "how much is the ferry ticket in Shanghai" in search box, hit Enter'); | ||
await sleep(5000); | ||
|
||
const relatedSearch = await agent.aiQuery('string[], related search keywords on the right'); | ||
console.log('related search', relatedSearch); | ||
expect(relatedSearch.length).toBeGreaterThan(3); | ||
}); | ||
}); |
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 |
---|---|---|
|
@@ -8,6 +8,6 @@ export default defineConfig({ | |
}, | ||
}, | ||
test: { | ||
include: [], | ||
include: ['./tests/puppeteer/*.spec.ts'], | ||
}, | ||
}); |