How to use deleteDeviceWithRetry method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

driver-e2e-specs.js

Source:driver-e2e-specs.js Github

copy

Full Screen

...32 });33 after(async function () {34 const sim = await getSimulator(caps.udid);35 await shutdownSimulator(sim);36 await deleteDeviceWithRetry(caps.udid);37 });38 afterEach(async function () {39 // try to get rid of the driver, so if a test fails the rest of the40 // tests aren't compromised41 await deleteSession();42 });43 if (!process.env.REAL_DEVICE) {44 it('should start and stop a session', async function () {45 driver = await initSession(baseCaps);46 let els = await driver.elementsByClassName("XCUIElementTypeWindow");47 els.length.should.be.at.least(1);48 });49 it('should start and stop a session doing pre-build', async function () {50 driver = await initSession(Object.assign({prebuildWDA: true}, baseCaps));51 let els = await driver.elementsByClassName("XCUIElementTypeWindow");52 els.length.should.be.at.least(1);53 });54 it('should start and stop a session doing simple build-test', async function () {55 driver = await initSession(Object.assign({useSimpleBuildTest: true}, baseCaps));56 let els = await driver.elementsByClassName("XCUIElementTypeWindow");57 els.length.should.be.at.least(1);58 });59 it('should start and stop a session with only bundle id', async function () {60 let localCaps = Object.assign({}, caps, {bundleId: 'com.example.apple-samplecode.UICatalog'});61 localCaps.app = null;62 await initSession(localCaps).should.not.eventually.be.rejected;63 });64 it('should start and stop a session with only bundle id when no sim is running', async function () {65 await killAllSimulators();66 let localCaps = Object.assign({}, caps, {bundleId: 'com.example.apple-samplecode.UICatalog'});67 localCaps.app = null;68 await initSession(localCaps).should.not.eventually.be.rejected;69 });70 it('should fail to start and stop a session if unknown bundle id used', async function () {71 let localCaps = Object.assign({}, caps, {bundleId: 'io.blahblahblah.blah'});72 localCaps.app = null;73 await initSession(localCaps).should.eventually.be.rejected;74 });75 it('should fail to start and stop a session if unknown bundle id used when no sim is running', async function () {76 await killAllSimulators();77 let localCaps = Object.assign({}, caps, {bundleId: 'io.blahblahblah.blah'});78 localCaps.app = null;79 await initSession(localCaps).should.eventually.be.rejected;80 });81 describe('WebdriverAgent port', function () {82 it('should run on default port if no other specified', async function () {83 let localCaps = Object.assign({}, baseCaps, {84 fullReset: true,85 useNewWDA: true,86 });87 localCaps.wdaLocalPort = null;88 driver = await initSession(localCaps);89 let logs = await driver.log('syslog');90 logs.some((line) => line.message.includes(':8100<-')).should.be.true;91 });92 it('should run on port specified', async function () {93 const localCaps = Object.assign({}, baseCaps, {94 fullReset: true,95 wdaLocalPort: 6000,96 useNewWDA: true,97 });98 driver = await initSession(localCaps);99 let logs = await driver.log('syslog');100 logs.some((line) => line.message.includes(':8100<-')).should.be.false;101 logs.some((line) => line.message.includes(':6000<-')).should.be.true;102 });103 });104 describe('initial orientation', async function () {105 async function runOrientationTest (initialOrientation) {106 let localCaps = _.defaults({107 orientation: initialOrientation108 }, caps);109 driver = await initSession(localCaps);110 let orientation = await driver.getOrientation();111 orientation.should.eql(initialOrientation);112 }113 for (let orientation of ['LANDSCAPE', 'PORTRAIT']) {114 it(`should be able to start in a ${orientation} mode`, async function () {115 this.timeout(MOCHA_TIMEOUT);116 await runOrientationTest(orientation);117 });118 }119 });120 describe('reset', function () {121 beforeEach(async function () {122 await retryInterval(5, 1000, async () => {123 await killAllSimulators();124 });125 });126 it.skip('default: creates sim and deletes it afterwards', async function () {127 let caps = UICATALOG_SIM_CAPS;128 await killAllSimulators();129 let simsBefore = await getNumSims();130 await initSession(caps);131 let simsDuring = await getNumSims();132 await deleteSession();133 let simsAfter = await getNumSims();134 simsDuring.should.equal(simsBefore + 1);135 simsAfter.should.equal(simsBefore);136 });137 it('with udid: uses sim and resets afterwards if resetOnSessionStartOnly is false', async function () {138 // before139 const udid = await createDevice(SIM_DEVICE_NAME,140 UICATALOG_SIM_CAPS.deviceName, UICATALOG_SIM_CAPS.platformVersion);141 let sim = await getSimulator(udid);142 await sim.run();143 // test144 let caps = _.defaults({145 udid,146 fullReset: true,147 resetOnSessionStartOnly: false148 }, UICATALOG_SIM_CAPS);149 (await sim.isRunning()).should.be.true;150 let simsBefore = await getNumSims();151 await initSession(caps);152 let simsDuring = await getNumSims();153 await deleteSession();154 let simsAfter = await getNumSims();155 (await sim.isRunning()).should.be.false;156 // make sure no new simulators were created during the test157 simsDuring.should.equal(simsBefore);158 simsAfter.should.equal(simsBefore);159 // cleanup160 await deleteDeviceWithRetry(udid);161 });162 it('with udid booted: uses sim and leaves it afterwards', async function () {163 // before164 const udid = await createDevice(SIM_DEVICE_NAME,165 UICATALOG_SIM_CAPS.deviceName, UICATALOG_SIM_CAPS.platformVersion);166 let sim = await getSimulator(udid);167 await sim.run();168 await B.delay(2000);169 // test170 let caps = _.defaults({171 udid,172 noReset: true173 }, UICATALOG_SIM_CAPS);174 (await sim.isRunning()).should.be.true;175 let simsBefore = await getNumSims();176 await initSession(caps);177 let simsDuring = await getNumSims();178 await deleteSession();179 let simsAfter = await getNumSims();180 (await sim.isRunning()).should.be.true;181 simsDuring.should.equal(simsBefore);182 simsAfter.should.equal(simsBefore);183 // cleanup184 await shutdownSimulator(sim);185 await deleteDeviceWithRetry(udid);186 });187 it('with invalid udid: throws an error', async function () {188 // test189 let caps = _.defaults({190 udid: 'some-random-udid'191 }, UICATALOG_SIM_CAPS);192 await initSession(caps).should.be.rejectedWith('Unknown device or simulator UDID');193 });194 it('with non-existent udid: throws an error', async function () {195 // test196 let udid = 'a77841db006fb1762fee0bb6a2477b2b3e1cfa7d';197 let caps = _.defaults({udid}, UICATALOG_SIM_CAPS);198 await initSession(caps).should.be.rejectedWith('Unknown device or simulator UDID');199 });200 it('with noReset set to true: leaves sim booted', async function () {201 this.timeout(MOCHA_TIMEOUT);202 // before203 const udid = await createDevice(SIM_DEVICE_NAME,204 UICATALOG_SIM_CAPS.deviceName, UICATALOG_SIM_CAPS.platformVersion);205 let sim = await getSimulator(udid);206 // some systems require a pause before initializing.207 await B.delay(2000);208 // test209 let caps = _.defaults({210 udid,211 noReset: true212 }, UICATALOG_SIM_CAPS);213 let simsBefore = await getNumSims();214 await initSession(caps);215 let simsDuring = await getNumSims();216 await deleteSession();217 let simsAfter = await getNumSims();218 (await sim.isRunning()).should.be.true;219 simsDuring.should.equal(simsBefore);220 simsAfter.should.equal(simsBefore);221 // cleanup222 await shutdownSimulator(sim);223 await deleteDeviceWithRetry(udid);224 });225 });226 describe('event timings', function () {227 it('should include event timings if cap is used', async function () {228 let newCaps = Object.assign({}, caps, {eventTimings: true});229 driver = await initSession(newCaps);230 let res = await driver.sessionCapabilities();231 should.exist(res.events);232 should.exist(res.events.newSessionStarted);233 res.events.newSessionStarted[0].should.be.above(res.events.newSessionRequested[0]);234 });235 });236 } else {237 // real device tests...

Full Screen

Full Screen

webdriveragent-derived-data-path-e2e-specs.js

Source:webdriveragent-derived-data-path-e2e-specs.js Github

copy

Full Screen

...34 });35 after(async function () {36 const sim = await getSimulator(caps.udid);37 await shutdownSimulator(sim);38 await deleteDeviceWithRetry(caps.udid);39 // delete created tmp folder40 fs.unlinkSync(TEMP_FOLDER);41 });42 afterEach(async function () {43 // try to get rid of the driver, so if a test fails the rest of the44 // tests aren't compromised45 await deleteSession();46 });47 if (!process.env.REAL_DEVICE) {48 it.skip('should start and stop a session', async function () {49 driver = await initSession(caps, this);50 let els = await driver.elementsByClassName('XCUIElementTypeWindow');51 els.length.should.be.at.least(1);52 });...

Full Screen

Full Screen

tvos-e2e-specs.js

Source:tvos-e2e-specs.js Github

copy

Full Screen

...26 platform: TVOS_CAPS.platformName,27 checkExistence: false,28 });29 await shutdownSimulator(sim);30 await deleteDeviceWithRetry(udid);31 }32 });33 beforeEach(function () {34 baseCaps = Object.assign({}, TVOS_CAPS, {udid});35 });36 afterEach(async function () {37 await deleteSession();38 });39 it('should launch com.apple.TVSettings', async function () {40 baseCaps.autoLaunch = true;41 const driver = await initSession(baseCaps);42 (await driver.elementByAccessibilityId('General')).should.exist;43 });44 it('should launch com.apple.TVSettings with autoLaunch false', async function () {...

Full Screen

Full Screen

simulator.js

Source:simulator.js Github

copy

Full Screen

1import _ from 'lodash';2import Simctl from 'node-simctl';3import { retryInterval } from 'asyncbox';4import { killAllSimulators as simKill } from 'appium-ios-simulator';5import { resetTestProcesses } from '../../../lib/utils';6async function killAllSimulators () {7 if (process.env.CLOUD) {8 return;9 }10 const simctl = new Simctl();11 const allDevices = _.flatMap(_.values(await simctl.getDevices()));12 const bootedDevices = allDevices.filter((device) => device.state === 'Booted');13 for (const {udid} of bootedDevices) {14 // It is necessary to stop the corresponding xcodebuild process before killing15 // the simulator, otherwise it will be automatically restarted16 await resetTestProcesses(udid, true);17 simctl.udid = udid;18 await simctl.shutdownDevice();19 }20 await simKill();21}22async function shutdownSimulator (device) {23 // stop XCTest processes if running to avoid unexpected side effects24 await resetTestProcesses(device.udid, true);25 await device.shutdown();26}27async function deleteDeviceWithRetry (udid) {28 const simctl = new Simctl({udid});29 try {30 await retryInterval(10, 1000, simctl.deleteDevice.bind(simctl));31 } catch (ign) {}32}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1driver.init({2}).then(function () {3 return driver.deleteDeviceWithRetry('device-id', 3, 1);4}).then(function () {5 console.log('Device deleted');6}).catch(function (err) {7 console.log('Error deleting device: ' + err);8});

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const { deleteDeviceWithRetry } = require('appium-xcuitest-driver/lib/utils');3const test = async () => {4 await driver.init({5 });6 const udid = await driver.sessionCapabilities().udid;7 await deleteDeviceWithRetry(udid);8 await driver.quit();9};10test();11const test = async () => {12 await driver.init({13 });14 const udid = await driver.sessionCapabilities().udid;15 await driver.deleteDeviceWithRetry(udid);16 await driver.quit();17};18test();19[HTTP] {}20[MJSONWP (0f5c6f8b)] Driver proxy active, passing request on via HTTP proxy21[debug] [JSONWP Proxy] Got response with status 200: "{\n \"value\" : \"\",\n

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var chai = require('chai');4var chaiAsPromised = require('chai-as-promised');5chai.use(chaiAsPromised);6var should = chai.should();7var expect = chai.expect;8var desired = {9};10 .init(desired)11 .setImplicitWaitTimeout(5000)12 .elementById('Clear')13 .click()14 .elementById('1')15 .click()16 .elementById('2')17 .click()18 .elementById('3')19 .click()20 .elementById('4')21 .click()22 .elementById('5')23 .click()24 .elementById('6')25 .click()26 .elementById('7')27 .click()28 .elementById('8')29 .click()30 .elementById('9')31 .click()32 .elementById('0')33 .click()34 .elementById('Equals')35 .click()36 .elementById('1234567890')37 .then(function () {38 return driver.deleteDeviceWithRetry();39 })40 .then(function () {41 return driver.quit();42 })43 .catch(function (err) {44 console.log(err);45 });

Full Screen

Using AI Code Generation

copy

Full Screen

1const { deleteDeviceWithRetry } = require('appium-xcuitest-driver');2const { retryInterval } = require('asyncbox');3const udids = ['udid1', 'udid2', 'udid3'];4const deleteDeviceWithRetry = retryInterval(3, 1000, async (udid) => {5 await deleteDeviceWithRetry(udid);6});7deleteDeviceWithRetry(udids);8"scripts": {9}

Full Screen

Using AI Code Generation

copy

Full Screen

1await driver.deleteDeviceWithRetry("deviceID", 5, 10);2commands.deleteDeviceWithRetry = async function (udid, retryCount, retryInterval) {3 let isDeleted = false;4 let count = 0;5 while (count < retryCount) {6 try {7 await this.deleteDevice(udid);8 isDeleted = true;9 break;10 } catch (err) {11 if (err.message.includes('Could not find device with id')) {12 isDeleted = true;13 break;14 }15 log.warn(`Unable to delete device with udid '${udid}'. Retrying after ${retryInterval} seconds...`);16 await B.delay(retryInterval * 1000);17 count++;18 }19 }20 return isDeleted;21};

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const { exec } = require('child_process');3const deleteDeviceWithRetry = (udid, retries) => {4 return new Promise((resolve, reject) => {5 const deleteDevice = () => {6 exec(`xcrun simctl delete ${udid}`, (err, stdout, stderr) => {7 if (stdout.includes('No devices are booted.')) {8 resolve();9 } else if (retries > 0) {10 setTimeout(deleteDevice, 1000);11 } else {12 reject(new Error(`Failed to delete device ${udid}`));13 }14 });15 };16 deleteDevice();17 });18};19const capabilities = {20};21const serverConfig = {22};23const driver = wd.promiseChainRemote(serverConfig);24 .init(capabilities)25 .then(() => {26 return driver.deleteDeviceWithRetry('udid', 3);27 })28 .then(() => {29 console.log('Device deleted successfully');30 })31 .catch((error) => {32 console.log(error);33 })34 .finally(() => {35 driver.quit();36 });

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