How to use this.remote.disconnect method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

swtclibInterface.js

Source:swtclibInterface.js Github

copy

Full Screen

...38            }).catch((error)=>{this.processError(error, resolve)})39        })40    }41    this.disconnect = function(){42        this.remote.disconnect()43    }44    this.close = function(){45        logger.debug('Trying to close at [' +this.url + ']!')46        if(this.remote.isConnected()) {47            this.remote.disconnect()48            logger.debug(this.url + ' is closed!')49        }50        logger.debug('All done!')51    }52    //endregion53    //region interfaces54    //region block number55    this.submitPromise_BlockNumber = function (resolve, reject) {56        this.remote.requestLedgerClosed().submitPromise()57            .then((data)=>{58                logger.debug(data)59                let response = this.createResponse(data.ledger_index)60                resolve(response)61            })62            .catch((error)=>{this.processError(error, resolve)})63    }64    //endregion65    //region block66    this.submitPromise_GetBlockByNumber = function (params, resolve, reject) {67        this.remote.requestLedger({68            ledger_index: params[0],69            transactions: params[1],70        }).submitPromise()71            .then((data)=>{72                logger.debug(data)73                let response = this.createResponse(data)74                resolve(response)75            })76            .catch((error)=>{this.processError(error, resolve)})77    }78    this.submitPromise_GetBlockByHash = function (params, resolve, reject) {79        this.remote.requestLedger({80            ledger_hash: params[0],81            transactions: params[1],82        }).submitPromise()83            .then((data)=>{84                logger.debug(data)85                let response = this.createResponse(data)86                resolve(response)87            })88            .catch((error)=>{this.processError(error, resolve)})89    }90    //endregion91    //region get tx92    this.submitPromise_GetTransactionByHash = function (params, resolve, reject) {93        this.remote.requestTx({94            hash: params[0],95        }).submitPromise()96            .then((data)=>{97                logger.debug(data)98                let response = this.createResponse(data)99                resolve(response)100            })101            .catch((error)=>{this.processError(error, resolve)})102    }103    //endregion104    //region account105    this.submitPromise_GetAccount = function (params, resolve, reject) {106        this.remote.requestAccountInfo({107            account: params[0],108        }).submitPromise()109            .then((data)=>{110                logger.debug(data)111                let response = this.createResponse(data.account_data)112                resolve(response)113            })114            .catch((error)=>{this.processError(error, resolve)})115    }116    //endregion117    //region balance118    this.submitPromise_GetBalance = function (params, resolve, reject) {119        this.remote.requestAccountInfo({120            account: params[0],121        }).submitPromise()122            .then((data)=>{123                logger.debug(data)124                let balance = data.account_data.Balance125                let response = this.createResponse({balance: balance})126                resolve(response)127            })128            .catch((error)=>{this.processError(error, resolve)})129    }130    //endregion131    //region send tx132    this.submitPromise_SendTx = function (params, resolve, reject) {133        let data = params[0]134        let options = {}135        if(data.from) options.source = data.from136        if(data.to) options.to = data.to137        if(data.value) options.amount = this.remote.makeAmount(data.value)138        if(data.sequence) options.sequence = data.sequence139        let secret = data.secret140        let memo = (data.memos != null && data.memos.length > 0) ? data.memos[0] : ''141        this.remote.buildPaymentTx(options)142            .submitPromise(secret, memo)143            .then((data)=>{144                logger.debug(data)145                let result = this.createSendTxResult(data)146                let success = this.checkResponse(data)147                if(success){148                    let response = this.createResponse(result)149                    resolve(response)150                }151                else{152                    this.processError(result, resolve)153                }154            })155            .catch((error)=>{156                this.processError(error, resolve)157            })158    }159    this.createSendTxResult = function(data){160        let result = {}161        result.engine_result = data.engine_result162        result.engine_result_code = data.engine_result_code163        result.engine_result_message = data.engine_result_message164        if(data.tx_json && data.tx_json.hash) result.hash = data.tx_json.hash165        return result166    }167    //endregion168    //region common methods169    swtclibInterface.prototype.getResponse = function (server, methodName, params) {170        baseInterface.prototype.getResponse(server, methodName, params)171        return new Promise(async (resolve, reject) => {172            if(this.remote.isConnected()){173                logger.debug("Remote is connected!")174            }175            else{176                logger.debug("Remote is not connected, trying to connect at [" + server.url + "]!")177                await server.connect()178            }179            server.processRequest(methodName, params, resolve, reject)180        })181    }182    this.processRequest = function(methodName, params, resolve, reject){183        if(methodName === consts.rpcFunctions.getBlockNumber){184            this.submitPromise_BlockNumber(resolve, reject)185        }186        else if(methodName === consts.rpcFunctions.getBlockByNumber){187            this.submitPromise_GetBlockByNumber(params, resolve, reject)188        }189        else if(methodName === consts.rpcFunctions.getBlockByHash){190            this.submitPromise_GetBlockByHash(params, resolve, reject)191        }192        else if(methodName === consts.rpcFunctions.getTransactionByHash){193            this.submitPromise_GetTransactionByHash(params, resolve, reject)194        }195        else if(methodName === consts.rpcFunctions.getAccount){196            this.submitPromise_GetAccount(params, resolve, reject)197        }198        else if(methodName === consts.rpcFunctions.getBalance){199            this.submitPromise_GetBalance(params, resolve, reject)200        }201        else if(methodName === consts.rpcFunctions.sendTx){202            this.submitPromise_SendTx(params, resolve, reject)203        }204    }205    //region create response206    this.createEmptyResponse = function(){207        let response = {}208        response.id = -1209        response.jsonrpc = '2.0'210        return response211    }212    this.createResponse = function(data){213        let response = this.createEmptyResponse()214        response.status = enums.responseStatus.success215        response.result = data216        return response217    }218    //endregion219    //region error process220    this.checkResponse = function(response){221        return response.engine_result === tesSUCCESS && response.engine_result_code === 0222    }223    this.createError = function(code, error){224        let response = this.createEmptyResponse()225        response.status = enums.responseStatus.error226        response.result = this.makeupErrorInfo(error)227        return response228    }229    this.makeupErrorInfo = function(error){230        let result = {}231        if(error == 'invalid ledger_index'232            || error == 'ledgerNotFound'233            || error == 'invalid account'234            || error == 'Account not found.'235            || error == 'invalid tx hash'236            || error == 'Transaction not found.'237        ){238            return error239        }240        if(error.engine_result){241            if(error.engine_result == consts.engineResults.temBAD_AMOUNT.engine_result){242                error.engine_result_message = consts.engineResults.temBAD_AMOUNT.engine_result_message243            }244            return error245        }246        if(error == 'No secret found for'247            || error == 'a valid secret is needed to sign with'){248            result = consts.engineResults.temINVALID_SECRET249        }250        else if (error == 'invalid source address'){251            result = consts.engineResults.temINVALID_FROM_ADDRESS252        }253        else if (error == 'invalid destination address'){254            result = consts.engineResults.temINVALID_TO_ADDRESS255        }256        else if (error == 'invalid amount'257            || error == "invalid amount: amount's maximum value is 100000000000"){258            result = consts.engineResults.temBAD_AMOUNT259        }260        else if (error == 'invalid sequence'){261            result = consts.engineResults.temBAD_SEQUENCE262        }263        else{264            result = consts.engineResults.temMALFORMED265        }266        result.engine_result_raw_error = error267        return result268    }269    this.processError = function(error, resolve){270        logger.error('Request swtclib error:' + JSON.stringify(error))271        resolve(this.createError(0, error))272        if(this.remote.isConnected()) this.remote.disconnect()273    }274    //endregion275    //endregion276    //endregion277}...

Full Screen

Full Screen

ios-hybrid.js

Source:ios-hybrid.js Github

copy

Full Screen

...156    throw new Error("Tried to leave a web frame but weren't in one");157  } else {158    var disconnect = function () {159      if (this.args.udid) {160        this.remote.disconnect(function () {});161      } else {162        this.remote.disconnect();163      }164      this.curContext = null;165      this.curWebFrames = [];166      this.curWebCoords = null;167      this.remote = null;168    }.bind(this);169    if (closeWindowBeforeDisconnecting) {170      this.closeWindow(disconnect);171    } else {172      disconnect();173    }174  }175};176module.exports = iOSHybrid;

Full Screen

Full Screen

RanvierTelnetInstance.js

Source:RanvierTelnetInstance.js Github

copy

Full Screen

1/*2 * Written by Kris Oye <kristianoye@gmail.com>3 * Copyright (C) 2017.  All rights reserved.4 * Date: October 1, 20175 *6 * Description: This module contains core game functionality.7 */89const10    ClientInstance = require('../../ClientInstance'),11    ClientCaps = require('../../ClientCaps'),12    uuidv1 = require('uuid/v1');1314class RanvierTelnetInstance extends ClientInstance {15    constructor(endpoint, client) {16        super(endpoint, client, client.remoteAddress);17        var mainWindow;1819        this.caps = new ClientCaps(this);2021        this.client.on('data', async (buffer) => {22            this.emit('kmud', {23                type: 'input',24                data: buffer.toString('utf8'),25                origin: this.mainWindow.id26            });27        });28        this.client.on('close', () => this.remoteDisconnect());29        this.client.on('disconnect', () => this.disconnect());30        this.client.on('drain', () => this.emit('drain'));31        this.closed = false;32        this.client.on('kmud', event => this.emit('kmud', event));33        this.client.on('window size', evt => {34            this.emit('kmud', {35                type: 'windowSize',36                data: evt37            });38        });39    }4041    eventSend(event) {42        switch (event.type) {43            case 'clearScreen':44                this.write("%^INITTERM%^");45                break;4647            case 'connected':48                this.writeLine(`Connected to ${event.data}`);49                break;5051            case 'disconnect':52                this.writeLine('Good-bye!');53                this.disconnect();54                break;5556            case 'prompt':57                this.renderPrompt(event.data);58                break;5960            case 'write':61                this.write(event.data);62                break;6364            default:65                break;66        }67    }6869    /*70     *  Programatically disconnect the client from the server.71     */72    close() {73        this.closed = true;74        this.client.end();75    }7677    async connect() {78        if (!this.mainWindow) {79            this.mainWindow = await ClientInstance.registerComponent(this, {80                type: 'MainWindow',81                attachTo: 'newLogin',82                id: uuidv1(),83                requiresShell: true84            });85        }86        return this.mainWindow;87    }8889    displayPrompt(evt) {90        if (this.inputStack.length === 0 && evt.prompt) {91            this.write(evt.prompt.text);92        }93        else if (this.inputStack.length === 1) {94            this.renderPrompt(this.inputStack[0]);95        }96    }9798    transmit(buffer) {99        if (!this.closed) this.client.transmit(buffer);100    }101102    get writable() {103        return !this.closed && this.client.writable;104    }105106    write(text) {107        if (!this.closed) {108            text = this.caps.html.renderHtml(text);109            text = this.caps.color.expandColors(text);110            return this.client.write(text);111        }112        return false;113    }114115    /**116     * Render a line of text to the client.117     * @param {string} text The text to render on the client.118     */119    writeLine(text) {120        this.write(!efuns.text.trailingNewline(text) ?121            text + efuns.eol : text);122    }123}124
...

Full Screen

Full Screen

device.js

Source:device.js Github

copy

Full Screen

...45	}46  onDelete() {47    clearInterval(this.timer);48    if (this.remote !== undefined) {49      this.remote.disconnect();50    }51  }52  sendCommand(cmd) {53    return new Promise(async (resolve, reject) => {54      let result = await this.remote.sendCommand(cmd);55      this.log(result);56      if (result && result.code === 200) {57        // All OK58        resolve(result.message);59      } else {60        let err = result ? result.message : 'Failure';61        reject(new Error(err));62      }63    })...

Full Screen

Full Screen

TuningScreen.js

Source:TuningScreen.js Github

copy

Full Screen

...19  }20  componentWillUnmount() {21    console.log("... TuningScreen.componentWillUnmount");22    this.remote.cancel();23    this.remote.disconnect();24  }25  render() {26    // TODO: disable all when bypassing effects27    return (28      <View style={styles.main}>29        <StatusBar backgroundColor="#145f9a" barStyle="light-content" />30        <Message text={this.state.message} spinner={this.state.initializing} />31        <FlatList32          data={this.state.effects}33          extraData={this.state}34          keyExtractor={(item) => item.id.toString()}35          renderItem={({item}) => (36            <BigSlider37              title={item.title}...

Full Screen

Full Screen

network.js

Source:network.js Github

copy

Full Screen

...34    }35  };36  Network.prototype.disconnect = function() {37    if (this.remote) {38      this.remote.disconnect();39    }40  };41  /**42   * Setup listeners for identity state.43   *44   * This function causes the network object to start listening to45   * changes in the identity state and automatically subscribe to46   * accounts accordingly.47   */48  Network.prototype.listenId = function (id)49  {50    var self = this;51  };52  Network.prototype.handleConnect = function (e)...

Full Screen

Full Screen

driver.js

Source:driver.js Github

copy

Full Screen

...47    log.info('Safari session ready to receive commands');48  }49  async deleteSession () {50    if (this.remote) {51      await this.remote.disconnect();52    }53    await super.deleteSession();54  }55  // TODO replace this stub56  isWebContext () {57    return true;58  }59  // TODO replace this stub60  isRealDevice () {61    return false;62  }63}64for (let [cmd, fn] of _.pairs(commands)) {65  SafariDriver.prototype[cmd] = fn;...

Full Screen

Full Screen

engine.js

Source:engine.js Github

copy

Full Screen

...60};61Engine.prototype.shutdown = function ()62{63  this.db.end();64  this.remote.disconnect();65};...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { remote } = require('webdriverio');2(async () => {3    const browser = await remote({4        capabilities: {5        }6    })7    await browser.remote.disconnect();8    await browser.deleteSession();9})().catch((e) => console.error(e))

Full Screen

Using AI Code Generation

copy

Full Screen

1const { remote } = require('webdriverio')2const caps = {3}4;(async function main () {5  try {6    const browser = await remote({7    })8    await browser.pause(5000)9    await browser.remote.disconnect()10  } catch (err) {11    console.error(err)12  }13})()14[HTTP] {}15[debug] [W3C (8a7b4a76)] Calling AppiumDriver.disconnect() with args: ["8a7b4a76-4c4f-4d3d-bc5b-3c1a7d2f2a3c"]16[debug] [W3C (8a7b4a76)] Responding to client with driver.disconnect() result: null17[HTTP] {}18[debug] [W3C (8a7b4a76)] Calling AppiumDriver.deleteSession() with args: ["8a7b

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3    .withCapabilities({4    })5    .build();6    .execute('mobile: remoteDebug', {action: 'connect'})7    .then(function() {8        console.log('Connected to remote debugger');9        return driver.execute('mobile: remoteDebug', {action: 'disconnect'});10    })11    .then(function() {12        console.log('Disconnected from remote debugger');13    })14    .then(function() {15        return driver.quit();16    })17    .catch(function(err) {18        console.log(err);19        return driver.quit();20    });21var webdriver = require('selenium-webdriver');22var driver = new webdriver.Builder()23    .withCapabilities({24    })25    .build();26    .execute('mobile: remoteDebug', {action: 'connect'})27    .then(function() {28        console.log('Connected to remote debugger');29        return driver.execute('mobile: debugger', {cmd: 'getTreeForXMLWithNodeIds'});30    })31    .then(function(res) {32        console.log('Got tree for XML with node IDs

Full Screen

Using AI Code Generation

copy

Full Screen

1describe('Test to disconnect remote', function() {2  it('should disconnect remote', function() {3    this.remote.disconnect()4  });5});6There is a bug in Appium Xcuitest Driver (

Full Screen

Using AI Code Generation

copy

Full Screen

1const XCUITestDriver = require('appium-xcuitest-driver');2let driver = new XCUITestDriver();3driver.connect();4driver.remote.disconnect();5driver.connect();6driver.remote.disconnect();7driver.connect();8driver.remote.disconnect();9driver.connect();10driver.remote.disconnect();11driver.connect();12driver.remote.disconnect();13driver.connect();14driver.remote.disconnect();15driver.connect();16driver.remote.disconnect();17driver.connect();18driver.remote.disconnect();19driver.connect();20driver.remote.disconnect();21driver.connect();22driver.remote.disconnect();23driver.connect();24driver.remote.disconnect();25driver.connect();26driver.remote.disconnect();27driver.connect();28driver.remote.disconnect();29driver.connect();30driver.remote.disconnect();31driver.connect();32driver.remote.disconnect();33driver.connect();34driver.remote.disconnect();35driver.connect();36driver.remote.disconnect();

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Appium Xcuitest Driver automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Sign up Free
_

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful