99 ITestStepHookParameter
1010} from '@cucumber/cucumber' ;
1111import defaultTimeouts from './defaultTimeouts' ;
12- import { Browser , BrowserContext , Page } from 'playwright' ;
12+ import { Browser , BrowserContext , Page , ElectronApplication } from 'playwright' ;
1313import { po } from '@qavajs/po-playwright' ;
1414import { driverProvider } from './driverProvider' ;
1515import {
@@ -50,8 +50,7 @@ Before({name: 'context init'}, async function () {
5050 config . driverConfig . capabilities . recordVideo = config . driverConfig . video ;
5151 }
5252 global . context = driverConfig . isElectron
53- //@ts -ignore
54- ? browser . context ( )
53+ ? ( browser as any as ElectronApplication ) . context ( )
5554 : await browser . newContext ( config ?. driverConfig ?. capabilities ) ;
5655 if ( config . driverConfig . trace ) {
5756 await context . tracing . start ( {
@@ -60,8 +59,7 @@ Before({name: 'context init'}, async function () {
6059 } ) ;
6160 }
6261 global . page = driverConfig . isElectron
63- //@ts -ignore
64- ? browser . firstWindow ( )
62+ ? await ( browser as any as ElectronApplication ) . firstWindow ( )
6563 : await context . newPage ( ) ;
6664 global . driver = global . browser ;
6765 po . init ( page , { timeout : config . driverConfig . timeout . present , logger : this } ) ;
@@ -106,8 +104,16 @@ After({name: 'context teardown'}, async function (scenario: ITestCaseHookParamet
106104 }
107105 global . contexts = null ;
108106 } else {
109- await context . close ( ) ;
110- this . log ( 'context closed' ) ;
107+ if ( ! config . driverConfig . isElectron ) {
108+ await context . close ( ) ;
109+ this . log ( 'context closed' ) ;
110+ } else {
111+ await ( browser as any as ElectronApplication )
112+ . evaluate ( ( main : any ) => { main . app . exit ( 0 ) } ) ;
113+ // @ts -ignore
114+ global . browser = null ;
115+ this . log ( 'electron app closed' ) ;
116+ }
111117 }
112118 }
113119 if ( saveVideo ( config . driverConfig , scenario ) ) {
@@ -121,6 +127,8 @@ After({name: 'context teardown'}, async function (scenario: ITestCaseHookParamet
121127
122128AfterAll ( async function ( ) {
123129 if ( global . browser ) {
124- await browser . close ( ) ;
130+ if ( ! config . driverConfig . isElectron ) {
131+ await browser . close ( ) ;
132+ }
125133 }
126134} ) ;
0 commit comments