UNPKG

appium-flutter-driver

Version:
60 lines 2.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.driverShouldDoProxyCmd = exports.getContexts = exports.setContext = exports.getCurrentContext = exports.NATIVE_CONTEXT_NAME = exports.FLUTTER_CONTEXT_NAME = void 0; const logger_1 = require("../logger"); exports.FLUTTER_CONTEXT_NAME = `FLUTTER`; exports.NATIVE_CONTEXT_NAME = `NATIVE_APP`; const getCurrentContext = async function () { return this.currentContext; }; exports.getCurrentContext = getCurrentContext; const setContext = async function (context) { if ([exports.FLUTTER_CONTEXT_NAME, exports.NATIVE_CONTEXT_NAME].includes(context)) { this.proxyWebViewActive = false; // Set 'native context' when flutter driver sets the context to FLUTTER_CONTEXT_NAME if (this.proxydriver) { logger_1.log.debug(`Setting downstream drier context to '${exports.NATIVE_CONTEXT_NAME}' in context '${context}'.`); // @ts-expect-error this exist in xcuitestdriver or uia2 driver await this.proxydriver.setContext(exports.NATIVE_CONTEXT_NAME); } } else { // this case may be 'webview' if (this.proxydriver) { logger_1.log.debug(`Setting downstream drier context to '${context}'.`); // @ts-expect-error this exist in xcuitestdriver or uia2 driver await this.proxydriver.setContext(context); this.proxyWebViewActive = true; } } this.currentContext = context; if (context === exports.FLUTTER_CONTEXT_NAME) { logger_1.log.debug(`Downstream driver context is set as 'NATIVE_APP' in 'FLUTTER' context to handle the native app.`); } }; exports.setContext = setContext; const getContexts = async function () { // @ts-expect-error this exist in xcuitestdriver or uia2 driver const nativeContext = await this.proxydriver?.getContexts(); if (nativeContext) { return [...nativeContext, exports.FLUTTER_CONTEXT_NAME]; } else { return [exports.FLUTTER_CONTEXT_NAME]; } }; exports.getContexts = getContexts; const driverShouldDoProxyCmd = function (command) { if (!this.proxydriver) { return false; } if (this.currentContext === exports.FLUTTER_CONTEXT_NAME) { return false; } if ([`getCurrentContext`, `setContext`, `getContexts`].includes(command)) { return false; } return true; }; exports.driverShouldDoProxyCmd = driverShouldDoProxyCmd; //# sourceMappingURL=context.js.map