@@ -245,7 +245,7 @@ class RecordActionTool implements RecorderTool {
245245 return ;
246246
247247 const checkbox = asCheckbox ( this . _recorder . deepEventTarget ( event ) ) ;
248- if ( checkbox ) {
248+ if ( checkbox && event . detail === 1 ) {
249249 // Interestingly, inputElement.checked is reversed inside this event handler.
250250 this . _performAction ( {
251251 name : checkbox . checked ? 'check' : 'uncheck' ,
@@ -335,30 +335,26 @@ class RecordActionTool implements RecorderTool {
335335 onPointerDown ( event : PointerEvent ) {
336336 if ( this . _shouldIgnoreMouseEvent ( event ) )
337337 return ;
338- if ( ! this . _performingActions . size )
339- consumeEvent ( event ) ;
338+ this . _consumeWhenAboutToPerform ( event ) ;
340339 }
341340
342341 onPointerUp ( event : PointerEvent ) {
343342 if ( this . _shouldIgnoreMouseEvent ( event ) )
344343 return ;
345- if ( ! this . _performingActions . size )
346- consumeEvent ( event ) ;
344+ this . _consumeWhenAboutToPerform ( event ) ;
347345 }
348346
349347 onMouseDown ( event : MouseEvent ) {
350348 if ( this . _shouldIgnoreMouseEvent ( event ) )
351349 return ;
352- if ( ! this . _performingActions . size )
353- consumeEvent ( event ) ;
350+ this . _consumeWhenAboutToPerform ( event ) ;
354351 this . _activeModel = this . _hoveredModel ;
355352 }
356353
357354 onMouseUp ( event : MouseEvent ) {
358355 if ( this . _shouldIgnoreMouseEvent ( event ) )
359356 return ;
360- if ( ! this . _performingActions . size )
361- consumeEvent ( event ) ;
357+ this . _consumeWhenAboutToPerform ( event ) ;
362358 }
363359
364360 onMouseMove ( event : MouseEvent ) {
@@ -448,7 +444,7 @@ class RecordActionTool implements RecorderTool {
448444 // Similarly to click, trigger checkbox on key event, not input.
449445 if ( event . key === ' ' ) {
450446 const checkbox = asCheckbox ( this . _recorder . deepEventTarget ( event ) ) ;
451- if ( checkbox ) {
447+ if ( checkbox && event . detail === 0 ) {
452448 this . _performAction ( {
453449 name : checkbox . checked ? 'uncheck' : 'check' ,
454450 selector : this . _activeModel ! . selector ,
@@ -472,7 +468,7 @@ class RecordActionTool implements RecorderTool {
472468 return ;
473469
474470 // Only allow programmatic keyups, ignore user input.
475- if ( ! this . _expectProgrammaticKeyUp ) {
471+ if ( this . _recorder . state . recorderMode === 'perform' && ! this . _expectProgrammaticKeyUp ) {
476472 consumeEvent ( event ) ;
477473 return ;
478474 }
@@ -486,7 +482,7 @@ class RecordActionTool implements RecorderTool {
486482 private _resetHoveredModel ( ) {
487483 this . _hoveredModel = null ;
488484 this . _hoveredElement = null ;
489- this . _recorder . updateHighlight ( null , false ) ;
485+ this . _updateHighlight ( false ) ;
490486 }
491487
492488 private _onFocus ( userGesture : boolean ) {
@@ -525,7 +521,8 @@ class RecordActionTool implements RecorderTool {
525521 }
526522
527523 // Consume event if action is not being executed.
528- consumeEvent ( event ) ;
524+ if ( this . _recorder . state . recorderMode === 'perform' )
525+ consumeEvent ( event ) ;
529526 return false ;
530527 }
531528
@@ -543,23 +540,40 @@ class RecordActionTool implements RecorderTool {
543540 return true ;
544541 }
545542
543+ private _consumeWhenAboutToPerform ( event : Event ) {
544+ if ( ! this . _performingActions . size && this . _recorder . state . recorderMode === 'perform' )
545+ consumeEvent ( event ) ;
546+ }
547+
546548 private _performAction ( action : actions . PerformOnRecordAction ) {
547549 this . _recorder . updateHighlight ( null , false ) ;
550+
551+ let promise = Promise . resolve ( ) ;
552+ if ( this . _recorder . state . recorderMode === 'perform' )
553+ promise = this . _innerPerformAction ( action ) ;
554+ else
555+ this . _recorder . recordAction ( action ) ;
556+
557+ if ( ! this . _recorder . injectedScript . isUnderTest )
558+ return ;
559+
560+ void promise . then ( ( ) => {
561+ // Serialize all to string as we cannot attribute console message to isolated world
562+ // in Firefox.
563+ console . error ( 'Action performed for test: ' + JSON . stringify ( { // eslint-disable-line no-console
564+ hovered : this . _hoveredModel ? ( this . _hoveredModel as any ) . selector : null ,
565+ active : this . _activeModel ? ( this . _activeModel as any ) . selector : null ,
566+ } ) ) ;
567+ } ) ;
568+ }
569+
570+ private async _innerPerformAction ( action : actions . PerformOnRecordAction ) {
548571 this . _performingActions . add ( action ) ;
549- void this . _recorder . performAction ( action ) . then ( ( ) => {
550- this . _performingActions . delete ( action ) ;
551572
573+ return this . _recorder . performAction ( action ) . then ( ( ) => {
574+ this . _performingActions . delete ( action ) ;
552575 // If that was a keyboard action, it similarly requires new selectors for active model.
553576 this . _onFocus ( false ) ;
554-
555- if ( this . _recorder . injectedScript . isUnderTest ) {
556- // Serialize all to string as we cannot attribute console message to isolated world
557- // in Firefox.
558- console . error ( 'Action performed for test: ' + JSON . stringify ( { // eslint-disable-line no-console
559- hovered : this . _hoveredModel ? ( this . _hoveredModel as any ) . selector : null ,
560- active : this . _activeModel ? ( this . _activeModel as any ) . selector : null ,
561- } ) ) ;
562- }
563577 } ) ;
564578 }
565579
@@ -601,14 +615,19 @@ class RecordActionTool implements RecorderTool {
601615 if ( ! this . _hoveredElement || ! this . _hoveredElement . isConnected ) {
602616 this . _hoveredModel = null ;
603617 this . _hoveredElement = null ;
604- this . _recorder . updateHighlight ( null , true ) ;
618+ this . _updateHighlight ( true ) ;
605619 return ;
606620 }
607621 const { selector, elements } = this . _recorder . injectedScript . generateSelector ( this . _hoveredElement , { testIdAttributeName : this . _recorder . state . testIdAttributeName } ) ;
608622 if ( this . _hoveredModel && this . _hoveredModel . selector === selector )
609623 return ;
610624 this . _hoveredModel = selector ? { selector, elements, color : HighlightColors . action } : null ;
611- this . _recorder . updateHighlight ( this . _hoveredModel , true ) ;
625+ this . _updateHighlight ( true ) ;
626+ }
627+
628+ private _updateHighlight ( userGesture : boolean ) {
629+ if ( this . _recorder . state . recorderMode === 'perform' || this . _recorder . injectedScript . isUnderTest )
630+ this . _recorder . updateHighlight ( this . _hoveredModel , userGesture ) ;
612631 }
613632}
614633
@@ -1041,6 +1060,7 @@ export class Recorder {
10411060 private _stylesheet : CSSStyleSheet ;
10421061 state : UIState = {
10431062 mode : 'none' ,
1063+ recorderMode : 'perform' ,
10441064 testIdAttributeName : 'data-testid' ,
10451065 language : 'javascript' ,
10461066 overlay : { offsetX : 0 } ,
0 commit comments