@@ -59,11 +59,11 @@ export class BrowserProxy {
5959 const originalUrl = browser . url . bind ( browser )
6060 const sessionCapturer = this . sessionCapturer
6161
62- browser . url = function ( url : string ) {
62+ browser . url = function ( url : string ) {
6363 const result = originalUrl ( url ) as any
6464
6565 if ( result && typeof result . perform === 'function' ) {
66- result . perform ( async function ( this : any ) {
66+ result . perform ( async function ( this : any ) {
6767 try {
6868 log . info ( `Injecting script after navigation to: ${ url } ` )
6969 await sessionCapturer . injectScript ( this )
@@ -83,7 +83,9 @@ export class BrowserProxy {
8383 * Wrap all browser commands to capture them
8484 */
8585 wrapBrowserCommands ( browser : NightwatchBrowser ) : void {
86- if ( this . browserProxied ) return
86+ if ( this . browserProxied ) {
87+ return
88+ }
8789
8890 const browserAny = browser as any
8991 const allMethods = new Set ( [
@@ -92,19 +94,31 @@ export class BrowserProxy {
9294 ] )
9395 const wrappedMethods : string [ ] = [ ]
9496
95- allMethods . forEach ( methodName => {
96- if ( methodName === 'constructor' || typeof browserAny [ methodName ] !== 'function' ) {
97+ allMethods . forEach ( ( methodName ) => {
98+ if (
99+ methodName === 'constructor' ||
100+ typeof browserAny [ methodName ] !== 'function'
101+ ) {
97102 return
98103 }
99104
100- if ( INTERNAL_COMMANDS_TO_IGNORE . includes ( methodName as any ) || methodName . startsWith ( '__' ) ) {
105+ if (
106+ INTERNAL_COMMANDS_TO_IGNORE . includes ( methodName as any ) ||
107+ methodName . startsWith ( '__' )
108+ ) {
101109 return
102110 }
103111
104112 const originalMethod = browserAny [ methodName ] . bind ( browser )
105113
106114 browserAny [ methodName ] = ( ...args : any [ ] ) => {
107- return this . handleCommandExecution ( browser , browserAny , methodName , originalMethod , args )
115+ return this . handleCommandExecution (
116+ browser ,
117+ browserAny ,
118+ methodName ,
119+ originalMethod ,
120+ args
121+ )
108122 }
109123
110124 wrappedMethods . push ( methodName )
@@ -126,7 +140,9 @@ export class BrowserProxy {
126140 ) : any {
127141 // Detect test boundaries
128142 const currentNightwatchTest = browserAny . currentTest
129- const currentTestName = this . testManager . detectTestBoundary ( currentNightwatchTest )
143+ const currentTestName = this . testManager . detectTestBoundary (
144+ currentNightwatchTest
145+ )
130146
131147 // Start test if this is its first command
132148 this . testManager . startTestIfPending ( currentTestName )
@@ -138,7 +154,11 @@ export class BrowserProxy {
138154 }
139155
140156 // Check for duplicate commands
141- const cmdSig = JSON . stringify ( { command : methodName , args, src : callInfo . callSource } )
157+ const cmdSig = JSON . stringify ( {
158+ command : methodName ,
159+ args,
160+ src : callInfo . callSource
161+ } )
142162 const isDuplicate = this . lastCommandSig === cmdSig
143163
144164 if ( ! isDuplicate ) {
@@ -155,16 +175,29 @@ export class BrowserProxy {
155175
156176 // Capture command after execution
157177 const stackFrame = this . commandStack [ this . commandStack . length - 1 ]
158- if ( stackFrame ?. command === methodName && stackFrame . signature === cmdSig ) {
178+ if (
179+ stackFrame ?. command === methodName &&
180+ stackFrame . signature === cmdSig
181+ ) {
159182 this . commandStack . pop ( )
160- this . captureCommandResult ( methodName , args , result , callInfo . callSource , browser , browserAny )
183+ this . captureCommandResult (
184+ methodName ,
185+ args ,
186+ result ,
187+ callInfo . callSource ,
188+ browser ,
189+ browserAny
190+ )
161191 }
162192
163193 return result
164194 } catch ( error ) {
165195 // Capture command error
166196 const stackFrame = this . commandStack [ this . commandStack . length - 1 ]
167- if ( stackFrame ?. command === methodName && stackFrame . signature === cmdSig ) {
197+ if (
198+ stackFrame ?. command === methodName &&
199+ stackFrame . signature === cmdSig
200+ ) {
168201 this . commandStack . pop ( )
169202 this . captureCommandError ( methodName , args , error , callInfo . callSource )
170203 }
@@ -185,12 +218,16 @@ export class BrowserProxy {
185218 browserAny : any
186219 ) : void {
187220 const currentTest = this . getCurrentTest ( )
188- if ( ! currentTest ) return
221+ if ( ! currentTest ) {
222+ return
223+ }
189224
190225 // Serialize result
191226 let serializedResult : any = undefined
192227 const isBrowserObject = result === browser || result === browserAny
193- const isChainableAPI = result && typeof result === 'object' &&
228+ const isChainableAPI =
229+ result &&
230+ typeof result === 'object' &&
194231 ( 'queue' in result || 'sessionId' in result || 'capabilities' in result )
195232
196233 if ( isBrowserObject || isChainableAPI ) {
@@ -211,16 +248,23 @@ export class BrowserProxy {
211248 }
212249
213250 // Capture and send command immediately
214- this . sessionCapturer . captureCommand (
215- methodName ,
216- args ,
217- serializedResult ,
218- undefined ,
219- currentTest . uid ,
220- callSource
221- ) . catch ( ( err : any ) => log . error ( `Failed to capture ${ methodName } : ${ err . message } ` ) )
222-
223- const lastCommand = this . sessionCapturer . commandsLog [ this . sessionCapturer . commandsLog . length - 1 ]
251+ this . sessionCapturer
252+ . captureCommand (
253+ methodName ,
254+ args ,
255+ serializedResult ,
256+ undefined ,
257+ currentTest . uid ,
258+ callSource
259+ )
260+ . catch ( ( err : any ) =>
261+ log . error ( `Failed to capture ${ methodName } : ${ err . message } ` )
262+ )
263+
264+ const lastCommand =
265+ this . sessionCapturer . commandsLog [
266+ this . sessionCapturer . commandsLog . length - 1
267+ ]
224268 if ( lastCommand ) {
225269 this . sessionCapturer . sendCommand ( lastCommand )
226270 }
@@ -236,18 +280,27 @@ export class BrowserProxy {
236280 callSource : string | undefined
237281 ) : void {
238282 const currentTest = this . getCurrentTest ( )
239- if ( ! currentTest ) return
240-
241- this . sessionCapturer . captureCommand (
242- methodName ,
243- args ,
244- undefined ,
245- error instanceof Error ? error : new Error ( String ( error ) ) ,
246- currentTest . uid ,
247- callSource
248- ) . catch ( ( err : any ) => log . error ( `Failed to capture ${ methodName } : ${ err . message } ` ) )
283+ if ( ! currentTest ) {
284+ return
285+ }
249286
250- const lastCommand = this . sessionCapturer . commandsLog [ this . sessionCapturer . commandsLog . length - 1 ]
287+ this . sessionCapturer
288+ . captureCommand (
289+ methodName ,
290+ args ,
291+ undefined ,
292+ error instanceof Error ? error : new Error ( String ( error ) ) ,
293+ currentTest . uid ,
294+ callSource
295+ )
296+ . catch ( ( err : any ) =>
297+ log . error ( `Failed to capture ${ methodName } : ${ err . message } ` )
298+ )
299+
300+ const lastCommand =
301+ this . sessionCapturer . commandsLog [
302+ this . sessionCapturer . commandsLog . length - 1
303+ ]
251304 if ( lastCommand ) {
252305 this . sessionCapturer . sendCommand ( lastCommand )
253306 }
0 commit comments