How to use runRealDeviceReset method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

driver.js

Source:driver.js Github

copy

Full Screen

...181 } else {182 logger.debug('Not clearing log files. Use `clearSystemFiles` capability to turn on.');183 }184 if (this.isRealDevice()) {185 await runRealDeviceReset(this.realDevice, this.opts);186 } else {187 await runSimulatorReset(this.sim, this.opts, this.keepAppToRetainPrefs);188 }189 await super.deleteSession();190 }191 async getSession () {192 let caps = await super.getSession();193 const viewportRect = await this.getViewportRect();194 const pixelRatio = await this.getDevicePixelRatio();195 const statBarHeight = await this.getStatusBarHeight();196 caps.viewportRect = viewportRect;197 caps.pixelRatio = pixelRatio;198 caps.statBarHeight = statBarHeight;199 return caps;200 }201 async executeCommand (cmd, ...args) {202 logger.debug(`Executing iOS command '${cmd}'`);203 if (cmd === 'receiveAsyncResponse') {204 return await this.receiveAsyncResponse(...args);205 } else if (this.ready || _.includes(['launchApp'], cmd)) {206 return await super.executeCommand(cmd, ...args);207 }208 throw new errors.NoSuchDriverError(`Driver is not ready, cannot execute ${cmd}.`);209 }210 // TODO: reformat this.helpers + configureApp211 async configureApp () {212 try {213 // if the app name is a bundleId assign it to the bundleId property214 if (!this.opts.bundleId && utils.appIsPackageOrBundle(this.opts.app)) {215 this.opts.bundleId = this.opts.app;216 }217 if (this.opts.app && this.opts.app.toLowerCase() === 'settings') {218 if (parseFloat(this.opts.platformVersion) >= 8) {219 logger.debug('We are on iOS8+ so not copying preferences app');220 this.opts.bundleId = 'com.apple.Preferences';221 this.opts.app = null;222 }223 } else if (this.opts.app && this.opts.app.toLowerCase() === 'calendar') {224 if (parseFloat(this.opts.platformVersion) >= 8) {225 logger.debug('We are on iOS8+ so not copying calendar app');226 this.opts.bundleId = 'com.apple.mobilecal';227 this.opts.app = null;228 }229 } else if (this.isSafari()) {230 if (!this.isRealDevice()) {231 if (parseFloat(this.opts.platformVersion) >= 8) {232 logger.debug('We are on iOS8+ so not copying Safari app');233 this.opts.bundleId = SAFARI_BUNDLE;234 this.opts.app = null;235 }236 } else {237 // on real device, need to check if safari launcher exists238 // first check if it is already on the device239 if (!await this.realDevice.isInstalled(this.opts.bundleId)) {240 // it's not on the device, so check if we need to build241 if (await needsInstall()) {242 logger.debug('SafariLauncher not found, building...');243 await install();244 }245 this.opts.bundleId = SAFARI_LAUNCHER_BUNDLE;246 }247 }248 } else if (this.opts.bundleId &&249 utils.appIsPackageOrBundle(this.opts.bundleId) &&250 (this.opts.app === '' || utils.appIsPackageOrBundle(this.opts.app))) {251 // we have a bundle ID, but no app, or app is also a bundle252 logger.debug('App is an iOS bundle, will attempt to run as pre-existing');253 } else {254 this.opts.app = await this.helpers.configureApp(this.opts.app, '.app');255 }256 } catch (err) {257 logger.error(err);258 throw new Error(259 `Bad app: ${this.opts.app}. App paths need to be absolute, or relative to the appium ` +260 'server install dir, or a URL to compressed file, or a special app name.');261 }262 }263 async startSimulator () {264 await utils.removeInstrumentsSocket(this.sock);265 if (!this.xcodeVersion) {266 logger.debug('Setting Xcode version');267 this.xcodeVersion = await utils.getAndCheckXcodeVersion(this.opts);268 logger.debug(`Xcode version set to ${this.xcodeVersion.versionString}`);269 }270 logger.debug('Setting iOS SDK Version');271 this.iosSdkVersion = await utils.getAndCheckIosSdkVersion();272 logger.debug(`iOS SDK Version set to ${this.iosSdkVersion}`);273 let timeout = _.isObject(this.opts.launchTimeout) ? this.opts.launchTimeout.global : this.opts.launchTimeout;274 let availableDevices = await retry(3, instrumentsUtils.getAvailableDevices, timeout);275 let iosSimUdid = await checkSimulatorAvailable(this.opts, this.iosSdkVersion, availableDevices);276 this.sim = await getSimulator(iosSimUdid, this.xcodeVersion.versionString);277 await moveBuiltInApp(this.sim);278 this.opts.localizableStrings = await utils.parseLocalizableStrings(this.opts);279 await utils.setBundleIdFromApp(this.opts);280 await this.createInstruments();281 {282 // previously setDeviceInfo()283 this.shouldPrelaunchSimulator = utils.shouldPrelaunchSimulator(this.opts, this.iosSdkVersion);284 let dString = await getAdjustedDeviceName(this.opts);285 if (this.caps.app) {286 await utils.setDeviceTypeInInfoPlist(this.opts.app, dString);287 }288 }289 await runSimulatorReset(this.sim, this.opts, this.keepAppToRetainPrefs);290 if (this.caps.customSSLCert && !this.isRealDevice()) {291 await installSSLCert(this.caps.customSSLCert, this.sim.udid);292 }293 if (this.opts.enableAsyncExecuteFromHttps && !this.isRealDevice()) {294 // await this.sim.shutdown();295 await this.startHttpsAsyncServer();296 }297 await isolateSimulatorDevice(this.sim, this.opts);298 this.localConfig = await setLocaleAndPreferences(this.sim, this.opts, this.isSafari(), endSimulator);299 await this.setUpLogCapture();300 await this.prelaunchSimulator();301 await this.startInstruments();302 await this.onInstrumentsLaunch();303 await this.configureBootstrap();304 await this.setBundleId();305 await this.setInitialOrientation();306 await this.initAutoWebview();307 await this.waitForAppLaunched();308 }309 async startRealDevice () {310 await utils.removeInstrumentsSocket(this.sock);311 this.opts.localizableStrings = await utils.parseLocalizableStrings(this.opts);312 await utils.setBundleIdFromApp(this.opts);313 await this.createInstruments();314 await runRealDeviceReset(this.realDevice, this.opts);315 await this.setUpLogCapture();316 await this.installToRealDevice();317 await this.startInstruments();318 await this.onInstrumentsLaunch();319 await this.configureBootstrap();320 await this.setBundleId();321 await this.setInitialOrientation();322 await this.initAutoWebview();323 await this.waitForAppLaunched();324 }325 async installToRealDevice () {326 // if user has passed in desiredCaps.autoLaunch = false327 // meaning they will manage app install / launching328 if (this.opts.autoLaunch === false) {...

Full Screen

Full Screen

device.js

Source:device.js Github

copy

Full Screen

1import _ from 'lodash';2import { getDeviceString } from 'appium-ios-simulator';3import path from 'path';4import * as utils from './utils';5import logger from './logger';6async function checkSimulatorAvailable (opts, sdkVersion, availableDevices) {7 if (sdkVersion < 7.1) {8 logger.debug('Instruments v < 7.1, not checking device string support');9 return;10 }11 logger.debug('Checking whether our device string is supported');12 let dString = await getAdjustedDeviceName(opts);13 let noDevicesError = function () {14 let msg = `Could not find a device to launch. You requested ` +15 `'${dString}', but the available devices were: ` +16 JSON.stringify(availableDevices);17 logger.errorAndThrow(msg);18 };19 if (sdkVersion >= 8) {20 let sim = utils.getSimForDeviceString(dString, availableDevices);21 if (sim[0] === null || sim[1] === null) {22 noDevicesError();23 }24 logger.debug(`iOS sim UDID is ${sim[1]}`);25 return sim[1];26 } else if (!_.includes(availableDevices, dString)) {27 noDevicesError();28 }29}30async function getAdjustedDeviceName (opts) {31 opts._adjustedDeviceName = opts._adjustedDeviceName || await getDeviceString(opts);32 return opts._adjustedDeviceName;33}34// TODO: what to do with this?35async function moveBuiltInApp (/*sim*/) {36 // call sim function once it is in place37}38async function runSimulatorReset (sim, opts, keepApp) {39 if (!opts.reset && !opts.fullReset) {40 logger.debug('Reset not set, not ending sim');41 return;42 }43 logger.debug('Running ios sim reset flow');44 // The simulator process must be ended before we delete applications.45 await endSimulator(sim);46 if (opts.fullReset) {47 logger.debug('Full reset is on, so erasing simulator');48 await fullResetSimulator(sim);49 } else if (opts.reset) {50 await resetSimulator(sim, opts, keepApp);51 }52}53async function fullResetSimulator (sim) {54 logger.debug('Cleaning the simulator');55 if (sim) {56 await sim.clean();57 }58}59async function resetSimulator (sim, opts, keepApp) {60 if (!sim) return; // eslint-disable-line curly61 logger.debug('Cleaning sim state.');62 try {63 await clearAppData(sim, opts, keepApp);64 } catch (err) {65 logger.warn(err);66 logger.warn('Could not reset simulator. Leaving as is.');67 }68}69async function endSimulator (sim) {70 if (!sim) return; // eslint-disable-line curly71 logger.debug('Killing the simulator');72 await sim.shutdown();73}74async function isolateSimulatorDevice (sim, opts, sdkVersion) {75 if (opts.isolateSimDevice && sdkVersion >= 8) {76 await sim.isolateSim();77 }78}79async function clearAppData (sim, opts, keepApp) {80 if (!keepApp && opts.app && opts.bundleId) {81 await sim.cleanCustomApp(path.basename(opts.app), opts.bundleId);82 }83}84async function resetRealDevice (device, opts) {85 if (opts.bundleId && opts.fullReset) {86 let bundleId = opts.bundleId;87 logger.debug(`Full reset requested. Will try to uninstall the app '${bundleId}'.`);88 if (!await device.isInstalled(bundleId)) {89 logger.debug('App not installed. No need to uninstall');90 return;91 }92 try {93 await device.remove(bundleId);94 } catch (err) {95 logger.error(`Could not remove '${bundleId}' from device`);96 throw err;97 }98 logger.debug(`Removed ${bundleId}`);99 }100}101async function runRealDeviceReset (device, opts) {102 if (opts.reset || opts.fullReset) {103 logger.debug('Running ios real device reset flow');104 if (opts.reset) {105 await resetRealDevice(device, opts);106 }107 } else {108 logger.debug('Reset not set, continuing');109 }110}111export {112 runSimulatorReset, isolateSimulatorDevice, checkSimulatorAvailable,113 moveBuiltInApp, getAdjustedDeviceName, endSimulator, runRealDeviceReset,...

Full Screen

Full Screen

real-device-management.js

Source:real-device-management.js Github

copy

Full Screen

1import { exec } from 'teen_process';2import log from './logger';3async function getConnectedDevices () {4 let {stdout} = await exec('idevice_id', ['-l']);5 return stdout.trim().split('\n');6}7async function resetRealDevice (device, opts) {8 if (opts.bundleId && opts.fullReset) {9 let bundleId = opts.bundleId;10 log.debug(`Full reset requested. Will try to uninstall the app '${bundleId}'.`);11 if (!await device.isInstalled(bundleId)) {12 log.debug('App not installed. No need to uninstall');13 return;14 }15 try {16 await device.remove(bundleId);17 } catch (err) {18 log.error(`Could not remove '${bundleId}' from device`);19 throw err;20 }21 log.debug(`Removed '${bundleId}'`);22 }23}24async function runRealDeviceReset (device, opts) {25 if (!opts.noReset || opts.fullReset) {26 log.debug('Running ios real device reset flow');27 if (!opts.noReset) {28 await resetRealDevice(device, opts);29 }30 } else {31 log.debug("Reset not set, continuing");32 }33}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2driver.init({3}).then(function () {4 return driver.runRealDeviceReset();5}).then(function () {6}).fin(function () { return driver.quit(); })7 .done();8var wd = require('wd');9driver.init({10}).then(function () {11 return driver.runRealDeviceReset();12}).then(function () {13}).fin(function () { return driver.quit(); })14 .done();15var wd = require('wd');16driver.init({17}).then(function () {18 return driver.runRealDeviceReset();19}).then(function () {20}).fin(function () { return driver.quit(); })21 .done();22var wd = require('wd');23driver.init({24}).then(function () {25 return driver.runRealDeviceReset();26}).then(function () {

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3 .forBrowser('xcuitest')4 .build();5driver.runRealDeviceReset()6 .then(function () {7 console.log('Real device reset successful');8 })9 .catch(function (err) {10 console.log('Real device reset failed');11 });12var webdriver = require('selenium-webdriver');13var driver = new webdriver.Builder()14 .forBrowser('xcuitest')15 .build();16driver.runRealDeviceReset()17 .then(function () {18 console.log('Real device reset successful');19 })20 .catch(function (err) {21 console.log('Real device reset failed');22 });

Full Screen

Using AI Code Generation

copy

Full Screen

1const { XCUITestDriver } = require('appium-xcuitest-driver');2const { ios } = require('appium-xcuitest-driver/lib/commands');3const { getSimulator } = require('appium-ios-simulator');4const { runRealDeviceReset } = ios.reset;5const driver = new XCUITestDriver();6const udid = 'udid of the device';7const opts = {8 device: await getSimulator(udid)9};10await runRealDeviceReset(opts);11await driver.deleteSession();12const { XCUITestDriver } = require('appium-xcuitest-driver');13const { ios } = require('appium-xcuitest-driver/lib/commands');14const { getSimulator } = require('appium-ios-simulator');15const { runRealDeviceReset } = ios.reset;16const driver = new XCUITestDriver();17const udid = 'udid of the device';18const opts = {19 device: await getSimulator(udid)20};21await runRealDeviceReset(opts);22await driver.deleteSession();23const { XCUITestDriver } = require('appium-xcuitest-driver');24const { ios } = require('appium-xcuitest-driver/lib/commands');25const { getSimulator } = require('appium-ios-simulator');26const { runRealDeviceReset } = ios.reset;27const driver = new XCUITestDriver();28const udid = 'udid of the device';29const opts = {30 device: await getSimulator(udid)31};32await runRealDeviceReset(opts);33await driver.deleteSession();34const { XCUITest

Full Screen

Using AI Code Generation

copy

Full Screen

1commands.runSimulatorReset = async function () {2 return await this._resetSimulator();3};4commands.runRealDeviceReset = async function () {5 return await this._resetRealDevice();6};7commands._resetSimulator = async function () {8 log.info('Resetting simulator');9 await this._deviceSandboxClean();10 await this._deviceSandboxRoot();11 await this._deviceSandboxClean();12 await this._deviceSandboxRoot();13 await this._deviceSandboxClean();14 await this._deviceSandboxRoot();15 log.info('Simulator reset finished');16};17commands._resetRealDevice = async function () {18 log.info('Resetting real device');19 await this._deviceSandboxClean();20 await this._deviceSandboxRoot();21 await this._deviceSandboxClean();22 await this._deviceSandboxRoot();23 await this._deviceSandboxClean();24 await this._deviceSandboxRoot();25 log.info('Real device reset finished');26};27commands._deviceSandboxRoot = async function () {28 if (this.isRealDevice()) {29 log.info('Rooting real device');30 await this._exec('idevicediagnostics', ['restart']);31 await this._exec('idevicediagnostics', ['root']);32 log.info('Real device rooted');33 } else {34 log.info('Rooting simulator');35 await this._exec('xcrun', ['simctl', 'spawn', this.opts.device.udid, 'launchctl', 'load', '/System/Library/LaunchDaemons/com.apple.mobile.installation.plist']);36 log.info('Simulator rooted');37 }38};39commands._deviceSandboxClean = async function () {40 if (this.isRealDevice()) {41 log.info('Cleaning real device');42 await this._exec('idevicediagnostics', ['restart']);43 await this._exec('idevicediagnostics', ['erase']);44 log.info('Real device cleaned');45 } else {46 log.info('Cleaning simulator');47 await this._exec('xcrun', ['simctl', 'erase', this.opts.device.udid]);48 log.info('Simulator

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const { assert } = require('chai');3const { AppiumDriver, AppiumServer, AppiumService } = require('appium');4async function main() {5 const driver = new AppiumDriver();6 const server = new AppiumServer({7 });8 await server.start();9 const appiumService = new AppiumService({10 });11 await appiumService.createSession({12 capabilities: {

Full Screen

Using AI Code Generation

copy

Full Screen

1const driver = wdio.remote(options);2await driver.runRealDeviceReset();3await driver.deleteSession();4await driver.runSimulatorReset()5const driver = wdio.remote(options);6await driver.runSimulatorReset();7await driver.deleteSession();8await driver.runSimulatorSecurity(command, args)9command: (string) The command to be executed10args: (string) The argument to be passed to the command11const driver = wdio.remote(options);12await driver.runSimulatorSecurity('touchid', 'enable');13await driver.deleteSession();14await driver.runWDAUpgrade()15const driver = wdio.remote(options);16await driver.runWDAUpgrade();17await driver.deleteSession();

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