1
- /* eslint-disable */
2
- const fs = require ( 'node:fs' )
3
- const { chromium, devices } = require ( 'playwright' )
1
+ import fs from 'node:fs'
2
+ import { chromium , devices , type BrowserContext , type BrowserContextOptions } from 'playwright'
4
3
5
4
const baseUrl = process . argv [ 2 ]
6
5
const outDir = process . argv [ 3 ] || 'screenshots'
@@ -11,29 +10,29 @@ const endpoints = {
11
10
SettingsActivity : '1d3dc3e03047b0c7/settings' ,
12
11
}
13
12
14
- async function takeScreenshots ( deviceType , context ) {
13
+ async function takeScreenshots ( deviceType : string , context : BrowserContext ) {
15
14
const page = await context . newPage ( )
16
15
for ( const [ route , path ] of Object . entries ( endpoints ) ) {
17
16
await page . goto ( `${ baseUrl } /${ path } ` , { waitUntil : 'networkidle' } )
18
- await page . waitForTimeout ( 2000 )
17
+ await page . waitForTimeout ( 500 )
19
18
await page . screenshot ( { path : `${ outDir } /${ route } -${ deviceType } .playwright.png` } )
20
19
console . log ( `${ route } -${ deviceType } .playwright.png` )
21
20
22
21
if ( route === 'Login' ) {
23
- await page . click ( ` button:has-text('Try the demo')` , { waitUntil : 'networkidle' } )
24
- await page . waitForTimeout ( 1000 )
22
+ await page . click ( ' button:has-text(\ 'Try the demo\')' )
23
+ await page . waitForLoadState ( 'networkidle' )
25
24
}
26
25
}
27
26
await page . close ( )
28
27
}
29
28
30
29
async function main ( ) {
31
- let executablePath = '/usr/bin/chromium'
30
+ let executablePath : string | undefined = '/usr/bin/chromium'
32
31
if ( ! fs . existsSync ( executablePath ) ) executablePath = undefined
33
32
34
33
const browser = await chromium . launch ( { executablePath, headless : true } )
35
34
36
- const contexts = [
35
+ const contexts : [ string , BrowserContextOptions ] [ ] = [
37
36
[ 'mobile' , devices [ 'iPhone 13' ] ] ,
38
37
[ 'desktop' , { viewport : { width : 1920 , height : 1080 } } ] ,
39
38
]
0 commit comments