@@ -31,7 +31,27 @@ export async function expectByPolling(
31
31
}
32
32
}
33
33
34
- export function setupPuppeteer ( args ?: string [ ] ) {
34
+ interface PuppeteerUtils {
35
+ page : ( ) => Page
36
+ click ( selector : string , options ?: ClickOptions ) : Promise < void >
37
+ count ( selector : string ) : Promise < number >
38
+ text ( selector : string ) : Promise < string | null >
39
+ value ( selector : string ) : Promise < string >
40
+ html ( selector : string ) : Promise < string >
41
+ classList ( selector : string ) : Promise < string [ ] >
42
+ children ( selector : string ) : Promise < any [ ] >
43
+ isVisible ( selector : string ) : Promise < boolean >
44
+ isChecked ( selector : string ) : Promise < boolean >
45
+ isFocused ( selector : string ) : Promise < boolean >
46
+ setValue ( selector : string , value : string ) : Promise < any >
47
+ typeValue ( selector : string , value : string ) : Promise < any >
48
+ enterValue ( selector : string , value : string ) : Promise < any >
49
+ clearValue ( selector : string ) : Promise < any >
50
+ timeout ( time : number ) : Promise < any >
51
+ nextFrame ( ) : Promise < any >
52
+ }
53
+
54
+ export function setupPuppeteer ( args ?: string [ ] ) : PuppeteerUtils {
35
55
let browser : Browser
36
56
let page : Page
37
57
@@ -69,35 +89,38 @@ export function setupPuppeteer(args?: string[]) {
69
89
await browser . close ( )
70
90
} )
71
91
72
- async function click ( selector : string , options ?: ClickOptions ) {
92
+ async function click (
93
+ selector : string ,
94
+ options ?: ClickOptions ,
95
+ ) : Promise < void > {
73
96
await page . click ( selector , options )
74
97
}
75
98
76
- async function count ( selector : string ) {
99
+ async function count ( selector : string ) : Promise < number > {
77
100
return ( await page . $$ ( selector ) ) . length
78
101
}
79
102
80
- async function text ( selector : string ) {
81
- return await page . $eval ( selector , node => node . textContent )
103
+ async function text ( selector : string ) : Promise < string | null > {
104
+ return page . $eval ( selector , node => node . textContent )
82
105
}
83
106
84
- async function value ( selector : string ) {
85
- return await page . $eval ( selector , node => ( node as HTMLInputElement ) . value )
107
+ async function value ( selector : string ) : Promise < string > {
108
+ return page . $eval ( selector , node => ( node as HTMLInputElement ) . value )
86
109
}
87
110
88
- async function html ( selector : string ) {
89
- return await page . $eval ( selector , node => node . innerHTML )
111
+ async function html ( selector : string ) : Promise < string > {
112
+ return page . $eval ( selector , node => node . innerHTML )
90
113
}
91
114
92
- async function classList ( selector : string ) {
93
- return await page . $eval ( selector , ( node : any ) => [ ...node . classList ] )
115
+ async function classList ( selector : string ) : Promise < string [ ] > {
116
+ return page . $eval ( selector , ( node : any ) => [ ...node . classList ] )
94
117
}
95
118
96
- async function children ( selector : string ) {
97
- return await page . $eval ( selector , ( node : any ) => [ ...node . children ] )
119
+ async function children ( selector : string ) : Promise < any [ ] > {
120
+ return page . $eval ( selector , ( node : any ) => [ ...node . children ] )
98
121
}
99
122
100
- async function isVisible ( selector : string ) {
123
+ async function isVisible ( selector : string ) : Promise < boolean > {
101
124
const display = await page . $eval ( selector , node => {
102
125
return window . getComputedStyle ( node ) . display
103
126
} )
0 commit comments