@@ -19,10 +19,8 @@ import path from 'path';
19
19
import fs from 'fs' ;
20
20
import { electronTest as test , expect } from './electronTest' ;
21
21
22
- test ( 'should fire close event' , async ( { playwright } ) => {
23
- const electronApp = await playwright . _electron . launch ( {
24
- args : [ path . join ( __dirname , 'electron-app.js' ) ] ,
25
- } ) ;
22
+ test ( 'should fire close event' , async ( { launchElectronApp } ) => {
23
+ const electronApp = await launchElectronApp ( 'electron-app.js' ) ;
26
24
const events = [ ] ;
27
25
electronApp . on ( 'close' , ( ) => events . push ( 'application' ) ) ;
28
26
electronApp . context ( ) . on ( 'close' , ( ) => events . push ( 'context' ) ) ;
@@ -33,22 +31,16 @@ test('should fire close event', async ({ playwright }) => {
33
31
expect ( events . join ( '|' ) ) . toBe ( 'context|application' ) ;
34
32
} ) ;
35
33
36
- test ( 'should dispatch ready event' , async ( { playwright } ) => {
37
- const electronApp = await playwright . _electron . launch ( {
38
- args : [ path . join ( __dirname , 'electron-app-ready-event.js' ) ] ,
39
- } ) ;
40
- try {
41
- const events = await electronApp . evaluate ( ( ) => globalThis . __playwrightLog ) ;
42
- expect ( events ) . toEqual ( [
43
- 'isReady == false' ,
44
- 'will-finish-launching fired' ,
45
- 'ready fired' ,
46
- 'whenReady resolved' ,
47
- 'isReady == true' ,
48
- ] ) ;
49
- } finally {
50
- await electronApp . close ( ) ;
51
- }
34
+ test ( 'should dispatch ready event' , async ( { launchElectronApp } ) => {
35
+ const electronApp = await launchElectronApp ( 'electron-app-ready-event.js' ) ;
36
+ const events = await electronApp . evaluate ( ( ) => globalThis . __playwrightLog ) ;
37
+ expect ( events ) . toEqual ( [
38
+ 'isReady == false' ,
39
+ 'will-finish-launching fired' ,
40
+ 'ready fired' ,
41
+ 'whenReady resolved' ,
42
+ 'isReady == true' ,
43
+ ] ) ;
52
44
} ) ;
53
45
54
46
test ( 'should script application' , async ( { electronApp } ) => {
@@ -114,28 +106,19 @@ test('should have a clipboard instance', async ({ electronApp }) => {
114
106
expect ( clipboardContentRead ) . toEqual ( clipboardContentToWrite ) ;
115
107
} ) ;
116
108
117
- test ( 'should test app that opens window fast' , async ( { playwright } ) => {
118
- const electronApp = await playwright . _electron . launch ( {
119
- args : [ path . join ( __dirname , 'electron-window-app.js' ) ] ,
120
- } ) ;
121
- await electronApp . close ( ) ;
109
+ test ( 'should test app that opens window fast' , async ( { launchElectronApp } ) => {
110
+ await launchElectronApp ( 'electron-window-app.js' ) ;
122
111
} ) ;
123
112
124
- test ( 'should return browser window' , async ( { playwright } ) => {
125
- const electronApp = await playwright . _electron . launch ( {
126
- args : [ path . join ( __dirname , 'electron-window-app.js' ) ] ,
127
- } ) ;
113
+ test ( 'should return browser window' , async ( { launchElectronApp } ) => {
114
+ const electronApp = await launchElectronApp ( 'electron-window-app.js' ) ;
128
115
const page = await electronApp . firstWindow ( ) ;
129
116
const bwHandle = await electronApp . browserWindow ( page ) ;
130
117
expect ( await bwHandle . evaluate ( ( bw : BrowserWindow ) => bw . title ) ) . toBe ( 'Electron' ) ;
131
- await electronApp . close ( ) ;
132
118
} ) ;
133
119
134
- test ( 'should bypass csp' , async ( { playwright, server } ) => {
135
- const app = await playwright . _electron . launch ( {
136
- args : [ require ( 'path' ) . join ( __dirname , 'electron-app.js' ) ] ,
137
- bypassCSP : true ,
138
- } ) ;
120
+ test ( 'should bypass csp' , async ( { launchElectronApp, server } ) => {
121
+ const app = await launchElectronApp ( 'electron-app.js' , { bypassCSP : true } ) ;
139
122
await app . evaluate ( electron => {
140
123
const window = new electron . BrowserWindow ( {
141
124
width : 800 ,
@@ -147,13 +130,10 @@ test('should bypass csp', async ({ playwright, server }) => {
147
130
await page . goto ( server . PREFIX + '/csp.html' ) ;
148
131
await page . addScriptTag ( { content : 'window["__injected"] = 42;' } ) ;
149
132
expect ( await page . evaluate ( 'window["__injected"]' ) ) . toBe ( 42 ) ;
150
- await app . close ( ) ;
151
133
} ) ;
152
134
153
- test ( 'should create page for browser view' , async ( { playwright } ) => {
154
- const app = await playwright . _electron . launch ( {
155
- args : [ path . join ( __dirname , 'electron-window-app.js' ) ] ,
156
- } ) ;
135
+ test ( 'should create page for browser view' , async ( { launchElectronApp } ) => {
136
+ const app = await launchElectronApp ( 'electron-window-app.js' ) ;
157
137
await app . firstWindow ( ) ;
158
138
await app . evaluate ( async electron => {
159
139
const window = electron . BrowserWindow . getAllWindows ( ) [ 0 ] ;
@@ -163,13 +143,10 @@ test('should create page for browser view', async ({ playwright }) => {
163
143
view . setBounds ( { x : 0 , y : 0 , width : 256 , height : 256 } ) ;
164
144
} ) ;
165
145
await expect . poll ( ( ) => app . windows ( ) . length ) . toBe ( 2 ) ;
166
- await app . close ( ) ;
167
146
} ) ;
168
147
169
- test ( 'should return same browser window for browser view pages' , async ( { playwright } ) => {
170
- const app = await playwright . _electron . launch ( {
171
- args : [ path . join ( __dirname , 'electron-window-app.js' ) ] ,
172
- } ) ;
148
+ test ( 'should return same browser window for browser view pages' , async ( { launchElectronApp } ) => {
149
+ const app = await launchElectronApp ( 'electron-window-app.js' ) ;
173
150
await app . firstWindow ( ) ;
174
151
await app . evaluate ( async electron => {
175
152
const window = electron . BrowserWindow . getAllWindows ( ) [ 0 ] ;
@@ -187,12 +164,10 @@ test('should return same browser window for browser view pages', async ({ playwr
187
164
} )
188
165
) ;
189
166
expect ( firstWindowId ) . toEqual ( secondWindowId ) ;
190
- await app . close ( ) ;
191
167
} ) ;
192
168
193
- test ( 'should record video' , async ( { playwright } , testInfo ) => {
194
- const app = await playwright . _electron . launch ( {
195
- args : [ path . join ( __dirname , 'electron-window-app.js' ) ] ,
169
+ test ( 'should record video' , async ( { launchElectronApp } , testInfo ) => {
170
+ const app = await launchElectronApp ( 'electron-window-app.js' , {
196
171
recordVideo : { dir : testInfo . outputPath ( 'video' ) }
197
172
} ) ;
198
173
const page = await app . firstWindow ( ) ;
@@ -203,25 +178,31 @@ test('should record video', async ({ playwright }, testInfo) => {
203
178
expect ( fs . statSync ( videoPath ) . size ) . toBeGreaterThan ( 0 ) ;
204
179
} ) ;
205
180
206
- test ( 'should be able to get the first window when with a delayed navigation' , async ( { playwright } ) => {
181
+ test ( 'should be able to get the first window when with a delayed navigation' , async ( { launchElectronApp } ) => {
207
182
test . info ( ) . annotations . push ( { type : 'issue' , description : 'https://github.com/microsoft/playwright/issues/17765' } ) ;
208
183
209
- const app = await playwright . _electron . launch ( {
210
- args : [ path . join ( __dirname , 'electron-window-app-delayed-loadURL.js' ) ] ,
211
- } ) ;
184
+ const app = await launchElectronApp ( 'electron-window-app-delayed-loadURL.js' ) ;
212
185
const page = await app . firstWindow ( ) ;
213
186
await expect ( page ) . toHaveURL ( 'data:text/html,<h1>Foobar</h1>' ) ;
214
187
await expect ( page . locator ( 'h1' ) ) . toHaveText ( 'Foobar' ) ;
215
- await app . close ( ) ;
216
188
} ) ;
217
189
218
- test ( 'should detach debugger on app-initiated exit' , async ( { playwright } ) => {
219
- const electronApp = await playwright . _electron . launch ( {
220
- args : [ path . join ( __dirname , 'electron-app.js' ) ] ,
221
- } ) ;
190
+ test ( 'should detach debugger on app-initiated exit' , async ( { launchElectronApp } ) => {
191
+ const electronApp = await launchElectronApp ( 'electron-app.js' ) ;
222
192
const closePromise = new Promise ( f => electronApp . process ( ) . on ( 'close' , f ) ) ;
223
193
await electronApp . evaluate ( ( { app } ) => {
224
194
app . quit ( ) ;
225
195
} ) ;
226
196
await closePromise ;
227
197
} ) ;
198
+
199
+ test ( 'should run pre-ready apis' , async ( { launchElectronApp } ) => {
200
+ await launchElectronApp ( 'electron-pre-ready-app.js' ) ;
201
+ } ) ;
202
+
203
+ test ( 'should resolve app path for folder apps' , async ( { launchElectronApp } ) => {
204
+ const electronApp = await launchElectronApp ( '.' ) ;
205
+ const appPath = await electronApp . evaluate ( async ( { app } ) => app . getAppPath ( ) ) ;
206
+ expect ( appPath ) . toBe ( path . resolve ( __dirname ) ) ;
207
+ await electronApp . close ( ) ;
208
+ } ) ;
0 commit comments