/**
 * Minified by jsDelivr using Terser v5.48.0.
 * Original file: /npm/appium-flutter-driver@4.0.0/build/lib/driver.js
 *
 * Do NOT use SRI with dynamically generated files! More information: https://www.jsdelivr.com/using-sri-with-dynamic-files
 */
import{XCUITestDriver}from"appium-xcuitest-driver";import{BaseDriver}from"appium/driver.js";import _ from"lodash";import{getClipboard,setClipboard}from"./commands/clipboard.js";import{driverShouldDoProxyCmd,FLUTTER_CONTEXT_NAME,getContexts,getCurrentContext,NATIVE_CONTEXT_NAME,setContext}from"./commands/context.js";import{clear,getText,setValue}from"./commands/element.js";import{execute}from"./commands/execute.js";import{click,longTap,performTouch,tap,tapEl}from"./commands/gesture.js";import{getScreenshot}from"./commands/screen.js";import{desiredCapConstraints}from"./desired-caps.js";import{log as logger}from"./logger.js";import{PLATFORM}from"./platform.js";import{executeElementCommand,executeGetVMCommand,executeGetIsolateCommand}from"./sessions/observatory.js";import{createSession,reConnectFlutterDriver}from"./sessions/session.js";const WEBVIEW_NO_PROXY=[["GET",new RegExp("^/session/[^/]+/appium")],["GET",new RegExp("^/session/[^/]+/context")],["GET",new RegExp("^/session/[^/]+/element/[^/]+/rect")],["GET",new RegExp("^/session/[^/]+/log/types$")],["GET",new RegExp("^/session/[^/]+/orientation")],["POST",new RegExp("^/session/[^/]+/appium")],["POST",new RegExp("^/session/[^/]+/context")],["POST",new RegExp("^/session/[^/]+/log$")],["POST",new RegExp("^/session/[^/]+/orientation")],["POST",new RegExp("^/session/[^/]+/touch/multi/perform")],["POST",new RegExp("^/session/[^/]+/touch/perform")]];class FlutterDriver extends BaseDriver{socket;locatorStrategies=["key","css selector"];proxydriver;device;portForwardLocalPort;localServer;connectedVmServiceUrl;internalCaps;receiveAsyncResponse;proxyWebViewActive=!1;executeElementCommand=executeElementCommand;executeGetVMCommand=executeGetVMCommand;executeGetIsolateCommand=executeGetIsolateCommand;execute=execute;executeAsync=execute;getText=getText;setValue=setValue;clear=clear;getScreenshot=getScreenshot;click=click;longTap=longTap;tapEl=tapEl;tap=tap;performTouch=performTouch;getContexts=getContexts;getClipboard=getClipboard;setClipboard=setClipboard;getCurrentContext=getCurrentContext;setContext=setContext;_logmon;currentContext=FLUTTER_CONTEXT_NAME;driverShouldDoProxyCmd=driverShouldDoProxyCmd;constructor(e,t){super(e,t),this.socket=null,this.device=null,this._logmon=null,this.desiredCapConstraints=desiredCapConstraints,this.portForwardLocalPort=null,this.connectedVmServiceUrl=null,this.localServer=null}async createSession(...e){const[t,r]=await super.createSession(...JSON.parse(JSON.stringify(e)));return this.internalCaps=r,createSession.bind(this)(t,r,...JSON.parse(JSON.stringify(e)))}async deleteSession(){switch(this.log.info("Deleting Flutter Driver session"),this._logmon?.stop(),this._logmon=null,this.proxydriver?.eventEmitter?.removeAllListeners("syslogStarted"),this.log.info("Cleanup the port forward"),_.toLower(this.internalCaps.platformName)){case PLATFORM.IOS:this.localServer?.close(),this.localServer=null;break;case PLATFORM.ANDROID:this.portForwardLocalPort&&this.proxydriver&&await(this.proxydriver.adb?.removePortForward(this.portForwardLocalPort))}if(this.connectedVmServiceUrl=null,this.proxydriver){this.log.info("Deleting the proxy driver session.");try{await this.proxydriver.deleteSession(this.sessionId||void 0)}catch(e){this.log.warn(e.message)}this.proxydriver=null}await super.deleteSession()}async installApp(e,t={}){await(this.proxydriver?.installApp(e,t))}async activateApp(e){await(this.proxydriver?.activateApp(e)),await reConnectFlutterDriver.bind(this)(this.internalCaps)}async terminateApp(e){return await(this.proxydriver?.terminateApp(e))}async back(){return await(this.proxydriver?.back())}async getOrientation(){return this.proxydriver?_.toLower(this.internalCaps.platformName)===PLATFORM.IOS?await this.proxydriver.proxyCommand("/orientation","GET"):await this.proxydriver.getOrientation():null}async setOrientation(e){return _.toLower(this.internalCaps.platformName)===PLATFORM.IOS?await this.proxydriver.proxyCommand("/orientation","POST",{orientation:e}):await this.proxydriver.setOrientation(e)}validateLocatorStrategy(e){if("NATIVE_APP"===this.currentContext)return this.proxydriver?.validateLocatorStrategy(e);super.validateLocatorStrategy(e,!1)}validateDesiredCaps(e){const t=super.validateDesiredCaps(e);return!!t||t}async proxyCommand(e,t,r=null){return await(this.proxydriver?.proxyCommand(e,t,r))}async executeCommand(e,...t){if(new RegExp(/^[\s]*mobile:[\s]*activateApp$/).test(t[0])){const{skipAttachObservatoryUrl:r=!1}=t[1][0];if(await(this.proxydriver?.executeCommand(e,...t)),r)return;return void await reConnectFlutterDriver.bind(this)(this.internalCaps)}if(new RegExp(/^[\s]*mobile:[\s]*terminateApp$/).test(t[0]))return await(this.proxydriver?.executeCommand(e,...t));if("receiveAsyncResponse"===e)return logger.debug(`Executing FlutterDriver response '${e}'`),await this.receiveAsyncResponse(...t);if(["setOrientation","getOrientation","back"].includes(e))return logger.debug(`Executing FlutterDriver command '${e}'`),await super.executeCommand(e,...t);if(this.driverShouldDoProxyCmd(e)){logger.debug(`Executing proxied driver command '${e}'`),await this.clearNewCommandTimeout();const r=await(this.proxydriver?.executeCommand(e,...t));return await this.startNewCommandTimeout(),r}return logger.debug(`Executing Flutter driver command '${e}'`),await super.executeCommand(e,...t)}getProxyAvoidList(){return[FLUTTER_CONTEXT_NAME,NATIVE_CONTEXT_NAME].includes(this.currentContext)?[]:WEBVIEW_NO_PROXY}proxyActive(){return this.proxyWebViewActive&&this.proxydriver?.constructor.name!==XCUITestDriver.name}canProxy(){return this.proxyWebViewActive}}export{FlutterDriver};
//# sourceMappingURL=/sm/bbae3e56c716c7759abc2683c6ea14e8896e552645b52fb4d624faf2c7f1ef47.map