UNPKG

appium-helios-driver

Version:
67 lines (56 loc) 1.87 kB
import { BaseDriver } from 'mx-appium-base-driver'; import { system } from 'appium-support'; import { AppiumForHelios, DEFAULT_A4M_HOST} from './appium-for-helios'; import logger from './logger'; // Appium instantiates this class class HeliosDriver extends BaseDriver { constructor (opts = {}, shouldValidateCaps = false) { super(opts, shouldValidateCaps); this.jwpProxyActive = false; this.opts.address = opts.address || DEFAULT_A4M_HOST; } async createSession (...args) { try { let [sessionId, caps] = await super.createSession(...args); await this.startHeliosForHeliosSession(); if (caps.app) { await this.a4mDriver.sendCommand('/url', 'POST', {url: caps.app}); } return [sessionId, caps]; } catch (e) { await this.deleteSession(); throw e; } } async startHeliosForHeliosSession () { this.a4mDriver = new AppiumForHelios(); await this.a4mDriver.startSession(this.caps); this.proxyReqRes = this.a4mDriver.proxyReqRes.bind(this.a4mDriver); // now that everything has started successfully, turn on proxying so all // subsequent session requests go straight to/from AppiumForHelios this.jwpProxyActive = true; } async deleteSession () { logger.debug('Deleting AppiumForHelios session'); if (this.a4mDriver && this.jwpProxyActive) { await this.a4mDriver.deleteSession(); await this.a4mDriver.stop(); this.a4mDriver = null; } this.jwpProxyActive = false; await super.deleteSession(); } proxyActive () { // we always have an active proxy to the AppiumForHelios server return true; } canProxy () { // we can always proxy to the AppiumForHelios server return true; } get driverData () { return {A4MPort: this.opts.port}; } } export { HeliosDriver }; export default HeliosDriver;