How to use this.wda.quit method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

driver.js

Source:driver.js Github

copy

Full Screen

...311 this.wda = new WebDriverAgent(this.xcodeVersion, this.opts);312 await this.wda.cleanupObsoleteProcesses();313 if (this.opts.useNewWDA) {314 log.debug(`Capability 'useNewWDA' set to true, so uninstalling WDA before proceeding`);315 await this.wda.quit();316 await this.wda.uninstall();317 this.logEvent('wdaUninstalled');318 } else if (!util.hasValue(this.wda.webDriverAgentUrl) && (await this.wda.isRunning())) {319 log.info(`Will reuse previously cached WDA instance at '${this.wda.url.href}'. ` +320 `Set the wdaLocalPort capability to a value different from ${this.wda.url.port} ` +321 `if this is an undesired behavior.`);322 this.wda.webDriverAgentUrl = this.wda.url.href;323 }324 // local helper for the two places we need to uninstall wda and re-start it325 const quitAndUninstall = async (msg) => {326 log.debug(msg);327 log.debug('Quitting and uninstalling WebDriverAgent, then retrying');328 await this.wda.quit();329 await this.wda.uninstall();330 throw new Error(msg);331 };332 const startupRetries = this.opts.wdaStartupRetries || (this.isRealDevice() ? WDA_REAL_DEV_STARTUP_RETRIES : WDA_SIM_STARTUP_RETRIES);333 const startupRetryInterval = this.opts.wdaStartupRetryInterval || WDA_STARTUP_RETRY_INTERVAL;334 await retryInterval(startupRetries, startupRetryInterval, async () => {335 this.logEvent('wdaStartAttempted');336 try {337 this.cachedWdaStatus = await this.wda.launch(sessionId, realDevice);338 } catch (err) {339 this.logEvent('wdaStartFailed');340 let errorMsg = `Unable to launch WebDriverAgent because of xcodebuild failure: "${err.message}".`;341 if (this.isRealDevice()) {342 errorMsg += ` Make sure you follow the tutorial at ${WDA_REAL_DEV_TUTORIAL_URL}. ` +343 `Try to remove the WebDriverAgentRunner application from the device if it is installed ` +344 `and reboot the device.`;345 }346 await quitAndUninstall(errorMsg);347 }348 this.proxyReqRes = this.wda.proxyReqRes.bind(this.wda);349 this.jwpProxyActive = true;350 try {351 await retryInterval(15, 1000, async () => {352 this.logEvent('wdaSessionAttempted');353 log.debug('Sending createSession command to WDA');354 try {355 this.cachedWdaStatus = this.cachedWdaStatus || await this.proxyCommand('/status', 'GET');356 await this.startWdaSession(this.opts.bundleId, this.opts.processArguments);357 } catch (err) {358 log.debug('Failed to create WDA session. Retrying...');359 throw err;360 }361 });362 this.logEvent('wdaSessionStarted');363 } catch (err) {364 let errorMsg = `Unable to start WebDriverAgent session because of xcodebuild failure: "${err.message}".`;365 if (this.isRealDevice()) {366 errorMsg += ` Make sure you follow the tutorial at ${WDA_REAL_DEV_TUTORIAL_URL}. ` +367 `Try to remove the WebDriverAgentRunner application from the device if it is installed ` +368 `and reboot the device.`;369 }370 await quitAndUninstall(errorMsg);371 }372 if (!util.hasValue(this.opts.preventWDAAttachments)) {373 // XCTest prior to Xcode 9 SDK has no native way to disable attachments374 this.opts.preventWDAAttachments = this.xcodeVersion.major < 9;375 if (this.opts.preventWDAAttachments) {376 log.info('Enabled WDA attachments prevention by default to save the disk space. ' +377 'Set preventWDAAttachments capability to false if this is an undesired behavior.');378 }379 }380 if (this.opts.preventWDAAttachments) {381 await adjustWDAAttachmentsPermissions(this.wda, this.opts.preventWDAAttachments ? '555' : '755');382 this.logEvent('wdaPermsAdjusted');383 }384 if (this.opts.clearSystemFiles) {385 await markSystemFilesForCleanup(this.wda);386 }387 // we expect certain socket errors until this point, but now388 // mark things as fully working389 this.wda.fullyStarted = true;390 this.logEvent('wdaStarted');391 });392 }393 // create an alias so we can actually unit test createSession by stubbing394 // this395 async extractBundleId (app) {396 return await appUtils.extractBundleId(app);397 }398 async runReset (opts = null) {399 this.logEvent('resetStarted');400 if (this.isRealDevice()) {401 await runRealDeviceReset(this.opts.device, opts || this.opts);402 } else {403 await runSimulatorReset(this.opts.device, opts || this.opts);404 }405 this.logEvent('resetComplete');406 }407 async deleteSession () {408 await SHARED_RESOURCES_GUARD.acquire(XCUITestDriver.name, async () => {409 await this.stop();410 // reset the permissions on the derived data folder, if necessary411 if (this.opts.preventWDAAttachments) {412 await adjustWDAAttachmentsPermissions(this.wda, '755');413 }414 if (this.opts.clearSystemFiles) {415 await clearSystemFiles(this.wda, !!this.opts.showXcodeLog);416 } else {417 log.debug('Not clearing log files. Use `clearSystemFiles` capability to turn on.');418 }419 });420 if (this.isWebContext()) {421 log.debug('In a web session. Removing remote debugger');422 await this.stopRemote();423 }424 if (this.opts.resetOnSessionStartOnly === false) {425 await this.runReset();426 }427 if (this.isSimulator() && this.opts.udid && this.opts.customSSLCert) {428 await uninstallSSLCert(this.opts.customSSLCert, this.opts.udid);429 }430 if (this.isSimulator() && !this.opts.noReset && !!this.opts.device) {431 if (this.lifecycleData.createSim) {432 await resetXCTestProcesses(this.opts.udid, true);433 log.debug(`Deleting simulator created for this run (udid: '${this.opts.udid}')`);434 await this.opts.device.shutdown();435 await this.opts.device.delete();436 }437 }438 if (!_.isEmpty(this.logs)) {439 this.logs.syslog.stopCapture();440 this.logs = {};441 }442 if (this.iwdpServer) {443 this.stopIWDP();444 }445 if (this.opts.enableAsyncExecuteFromHttps && !this.isRealDevice()) {446 await this.stopHttpsAsyncServer();447 }448 this.resetIos();449 await super.deleteSession();450 }451 async stop () {452 this.jwpProxyActive = false;453 this.proxyReqRes = null;454 if (this.wda && this.wda.fullyStarted) {455 if (this.wda.jwproxy) {456 try {457 await this.proxyCommand(`/session/${this.sessionId}`, 'DELETE');458 } catch (err) {459 // an error here should not short-circuit the rest of clean up460 log.debug(`Unable to DELETE session on WDA: '${err.message}'. Continuing shutdown.`);461 }462 }463 if (this.wda && !this.wda.webDriverAgentUrl && this.opts.useNewWDA) {464 await this.wda.quit();465 }466 }467 }468 async executeCommand (cmd, ...args) {469 log.debug(`Executing command '${cmd}'`);470 if (cmd === 'receiveAsyncResponse') {471 return await this.receiveAsyncResponse(...args);472 }473 // TODO: once this fix gets into base driver remove from here474 if (cmd === 'getStatus') {475 return await this.getStatus();476 }477 return await super.executeCommand(cmd, ...args);478 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const wdio = require('webdriverio');2const opts = {3 capabilities: {4 },5};6(async () => {7 const client = await wdio.remote(opts);8 await client.pause(10000);9 await client.wda.quit();10 await client.pause(10000);11})();12const wdio = require('webdriverio');13const opts = {14 capabilities: {15 },16};17(async () => {18 const client = await wdio.remote(opts);19 await client.pause(10000);20 await client.wda.quit();21 await client.pause(10000);22})();23const wdio = require('webdriverio');24const opts = {25 capabilities: {26 },27};28(async () => {29 const client = await wdio.remote(opts);30 await client.pause(10000);31 await client.wda.quit();32 await client.pause(10000);33})();

Full Screen

Using AI Code Generation

copy

Full Screen

1this.wda.quit();2async quit () {3 if (this.wda) {4 await this.wda.quit();5 }6 if (this.xcodebuild) {7 await this.xcodebuild.quit();8 }9 if (this.simctl) {10 await this.simctl.shutdown();11 }12 }13}

Full Screen

Using AI Code Generation

copy

Full Screen

1const wdio = require('webdriverio');2const opts = {3 capabilities: {4 }5};6(async function() {7 const client = await wdio.remote(opts);8 await client.pause(5000);9 await client.wda.quit();10})();11const wdio = require('webdriverio');12const opts = {13 capabilities: {14 }15};16(async function() {17 const client = await wdio.remote(opts);18 await client.pause(5000);19 await client.wda.quit();20})();

Full Screen

Using AI Code Generation

copy

Full Screen

1async quit () {2 await this.wda.quit();3}4async quit () {5 await this.proxyCommand('/wda/quit', 'POST');6}7async proxyCommand (url, method, body = null) {8 let res = await this.jwproxy.command(url, method, body);9}10async command (url, method, body = null) {11 let res = await this.doCommand(url, method, body);12}13async doCommand (url, method, body = null) {14 let {protocol, host, port} = this.server;15}16get server () {17 let {host, port} = this.session;18}19get session () {20 return this.sessionId ? {sessionId: this.sessionId} : {};21}22get sessionId () {23 return this.sessionId;24}25set sessionId (sessionId) {26 this.sessionId = sessionId;27}28async doCommand (url, method, body = null) {

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const chai = require('chai');3const chaiAsPromised = require('chai-as-promised');4chai.use(chaiAsPromised);5const should = chai.should();6const { exec } = require('child_process');7const { retryInterval } = require('asyncbox');8const { fs, logger } = require('appium-support');9const { waitForCondition } = require('asyncbox');10const log = logger.getLogger('WDA-QUIT');11const HOST = 'localhost';12const PORT = 4723;13const BUNDLE_ID = 'com.apple.mobilecal';14let driver;15let caps = {16};17async function startWda () {18 log.info('Starting WDA');19 await driver.startWda();20 log.info('WDA started');21}22async function quitWda () {23 log.info('Quitting WDA');24 await driver.quitWda();25 log.info('WDA quit');26}27async function wdaPid () {28 const cmd = 'pgrep -f WebDriverAgentRunner';29 const {stdout} = await exec(cmd);30 return parseInt(stdout, 10);31}32async function waitForWdaPidToDisappear () {33 await waitForCondition(async () => {34 const pid = await wdaPid();35 return !pid;36 }, {37 });38}39async function waitForWdaPidToAppear () {40 await waitForCondition(async () => {41 const pid = await wdaPid();42 return pid;43 }, {44 });45}46async function checkWdaPid () {47 const pid = await wdaPid();48 if (!pid) {49 throw new Error('WDA process not running');50 }51}52async function checkWdaPidIsNotRunning () {53 const pid = await wdaPid();54 if (pid) {55 throw new Error('WDA process is running');56 }57}58async function checkWdaPidIsRunning () {

Full Screen

Using AI Code Generation

copy

Full Screen

1await this.wda.quit();2commands.quit = async function () {3 await this.wda.quit();4};5async quit () {6 await this.proxyCommand('/wda/quit', 'POST');7};8async proxyCommand (url, method, body = null, retryCount = 0) {9 const realUrl = this.getUrl(url);10 const opts = {11 headers: {12 },13 };14 if (body) {15 opts.body = body;16 }17 try {18 const res = await request(opts);19 return res.body;20 } catch (err) {21 if (err.statusCode === 500 && retryCount < 3) {22 log.debug(`WDA quit returned 500. Retrying ${retryCount + 1} time`);23 return await this.proxyCommand(url, method, body, retryCount + 1);24 }25 throw err;26 }27};28getUrl (url) {29 return `${this.urlBase}${url}`;30};31get urlBase () {32};33async start (sessionId, caps) {34 this.port = await getFreePort();35};36async start (sessionId, caps) {37 await this.startWdaSession(session

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const path = require('path');3const assert = require('assert');4const iosApp = path.resolve('./ios-apps/UICatalog.app.zip');5const config = {6};7const driver = wd.promiseChainRemote('localhost', 4723);8 .init(config)9 .then(() => {10 console.log('driver is initialized');11 })12 .quit()13 .then(() => {14 console.log('driver is quit');15 })16 .catch((err) => {17 console.log('error', err);18 });

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