@@ -34,7 +34,6 @@ import {
3434import type { FormatFileNameOptions , GetAndCreatePathOptions } from './utils.interfaces.js'
3535import { IMAGE_STRING } from '../mocks/mocks.js'
3636import { DEVICE_RECTANGLES } from './constants.js'
37- import { injectWebviewOverlay } from '../clientSideScripts/injectWebviewOverlay.js'
3837import { getMobileWebviewClickAndDimensions } from '../clientSideScripts/getMobileWebviewClickAndDimensions.js'
3938import { checkMetaTag } from '../clientSideScripts/checkMetaTag.js'
4039import type { ClassOptions } from './options.interfaces.js'
@@ -737,51 +736,60 @@ describe('utils', () => {
737736
738737 describe ( 'executeNativeClick' , ( ) => {
739738 const coords = { x : 100 , y : 200 }
739+ let mockBrowser : any
740+
741+ beforeEach ( async ( ) => {
742+ vi . clearAllMocks ( )
743+ const { browser } = await vi . importMock ( '@wdio/globals' ) as any
744+ mockBrowser = browser
745+ } )
740746
741747 afterEach ( ( ) => {
742748 vi . clearAllMocks ( )
743749 } )
744750
745- it ( 'should call executor with "mobile: tap" on iOS' , async ( ) => {
746- const executor = vi . fn ( )
747- await executeNativeClick ( { executor, isIOS : true , ...coords } )
751+ it ( 'should call browser.execute with "mobile: tap" on iOS' , async ( ) => {
752+ mockBrowser . execute = vi . fn ( )
753+
754+ await executeNativeClick ( { isIOS : true , ...coords } )
748755
749- expect ( executor ) . toHaveBeenCalledWith ( 'mobile: tap' , coords )
756+ expect ( mockBrowser . execute ) . toHaveBeenCalledWith ( 'mobile: tap' , coords )
750757 } )
751758
752- it ( 'should call executor with "mobile: clickGesture" on Android (Appium 2)' , async ( ) => {
753- const executor = vi . fn ( )
754- await executeNativeClick ( { executor, isIOS : false , ...coords } )
759+ it ( 'should call browser.execute with "mobile: clickGesture" on Android (Appium 2)' , async ( ) => {
760+ mockBrowser . execute = vi . fn ( )
761+
762+ await executeNativeClick ( { isIOS : false , ...coords } )
755763
756- expect ( executor ) . toHaveBeenCalledWith ( 'mobile: clickGesture' , coords )
764+ expect ( mockBrowser . execute ) . toHaveBeenCalledWith ( 'mobile: clickGesture' , coords )
757765 } )
758766
759767 it ( 'should fall back to "doubleClickGesture" when clickGesture fails (Appium 1)' , async ( ) => {
760- const executor = vi . fn ( )
768+ mockBrowser . execute = vi . fn ( )
761769 . mockRejectedValueOnce ( new Error ( 'WebDriverError: Unknown mobile command: clickGesture' ) )
762770 . mockResolvedValueOnce ( undefined )
763771 const logWarnMock = vi . spyOn ( log , 'warn' )
764772
765- await executeNativeClick ( { executor , isIOS : false , ...coords } )
773+ await executeNativeClick ( { isIOS : false , ...coords } )
766774
767- expect ( executor ) . toHaveBeenCalledWith ( 'mobile: clickGesture' , coords )
768- expect ( executor ) . toHaveBeenCalledWith ( 'mobile: doubleClickGesture' , coords )
775+ expect ( mockBrowser . execute ) . toHaveBeenCalledWith ( 'mobile: clickGesture' , coords )
776+ expect ( mockBrowser . execute ) . toHaveBeenCalledWith ( 'mobile: doubleClickGesture' , coords )
769777 expect ( logWarnMock ) . toHaveBeenCalledWith ( expect . stringContaining ( 'falling back to `doubleClickGesture`' ) )
770778
771779 logWarnMock . mockRestore ( )
772780 } )
773781
774782 it ( 'should throw the error if it\'s not a known Appium command error' , async ( ) => {
775- const executor = vi . fn ( ) . mockRejectedValueOnce ( new Error ( 'Some unexpected error' ) )
783+ mockBrowser . execute = vi . fn ( ) . mockRejectedValueOnce ( new Error ( 'Some unexpected error' ) )
776784
777- await expect ( executeNativeClick ( { executor , isIOS : false , ...coords } ) )
785+ await expect ( executeNativeClick ( { isIOS : false , ...coords } ) )
778786 . rejects
779787 . toThrowError ( 'Some unexpected error' )
780788 } )
781789 } )
782790
783791 describe ( 'getMobileViewPortPosition' , ( ) => {
784- const mockExecutor = vi . fn ( )
792+ let mockBrowser : any
785793 const mockUrl = vi . fn ( )
786794 const mockGetUrl = vi . fn ( ) . mockResolvedValue ( 'http://example.com' )
787795
@@ -793,22 +801,23 @@ describe('utils', () => {
793801 screenHeight : 800 ,
794802 screenWidth : 400 ,
795803 methods : {
796- executor : mockExecutor ,
797804 url : mockUrl ,
798805 getUrl : mockGetUrl ,
799806 } ,
800807 }
801808
802- beforeEach ( ( ) => {
809+ beforeEach ( async ( ) => {
803810 vi . clearAllMocks ( )
811+ const { browser } = await vi . importMock ( '@wdio/globals' ) as any
812+ mockBrowser = browser
804813 } )
805814
806815 it ( 'should return correct device rectangles for iOS WebView flow' , async ( ) => {
807- mockExecutor
808- . mockResolvedValueOnce ( undefined ) // executor for the blob ( loadBase64Html)
809- . mockResolvedValueOnce ( undefined ) // checkMetaTag (loadBase64Html)
816+ mockBrowser . execute = vi . fn ( )
817+ . mockResolvedValueOnce ( undefined ) // loadBase64Html
818+ . mockResolvedValueOnce ( undefined ) // checkMetaTag
810819 . mockResolvedValueOnce ( undefined ) // injectWebviewOverlay
811- . mockResolvedValueOnce ( undefined ) // nativeClick
820+ . mockResolvedValueOnce ( undefined ) // executeNativeClick
812821 . mockResolvedValueOnce ( { x : 150 , y : 300 , width : 100 , height : 100 } ) // getMobileWebviewClickAndDimensions
813822
814823 const result = await getMobileViewPortPosition ( {
@@ -818,8 +827,7 @@ describe('utils', () => {
818827
819828 expect ( mockGetUrl ) . toHaveBeenCalled ( )
820829 expect ( mockUrl ) . toHaveBeenCalledTimes ( 1 )
821- expect ( mockExecutor ) . toHaveBeenCalledWith ( injectWebviewOverlay , false )
822- expect ( mockExecutor ) . toHaveBeenCalledWith ( getMobileWebviewClickAndDimensions , '[data-test="ics-overlay"]' )
830+ expect ( mockBrowser . execute ) . toHaveBeenCalledWith ( getMobileWebviewClickAndDimensions , '[data-test="ics-overlay"]' )
823831
824832 expect ( result ) . toMatchSnapshot ( )
825833 } )
@@ -832,7 +840,7 @@ describe('utils', () => {
832840 } )
833841
834842 expect ( result ) . toEqual ( DEVICE_RECTANGLES )
835- expect ( mockExecutor ) . not . toHaveBeenCalled ( )
843+ expect ( mockBrowser . execute ) . not . toHaveBeenCalled ( )
836844 } )
837845
838846 it ( 'should return initialDeviceRectangles if Android + not nativeWebScreenshot' , async ( ) => {
0 commit comments