How to use installToRealDevice method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

driver.js

Source:driver.js Github

copy

Full Screen

...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) {329      return;330    }...

Full Screen

Full Screen

safari.js

Source:safari.js Github

copy

Full Screen

1"use strict";2var IOS = require('./ios.js')3  , logger = require('../../server/logger.js').get('appium')4  , path = require('path')5  , _ = require('underscore');6var NATIVE_REAL_SAFARI_MIN_VER = 7.07  , SAFARI_BUNDLE = 'com.apple.mobilesafari';8var Safari = function () {9  this.init();10  this.landscapeWebCoordsOffset = 40;11};12_.extend(Safari.prototype, IOS.prototype);13Safari.prototype.configure = function (args, caps, cb) {14  logger.debug("Configuring Safari session");15  this._deviceConfigure(args, caps);16  this.setIOSArgs();17  this.capabilities.safari = true;18  if (this.args.udid) {19    this.dontCleanupSession = true;20    this.args.app = path.resolve(__dirname,21        "../../../build/SafariLauncher/SafariLauncher.zip");22    this.configureLocalApp(cb);23  } else {24    if (parseFloat(this.args.platformVersion) >= 8) {25      logger.debug("We're on iOS8+ so not copying mobile safari app");26      this.args.bundleId = SAFARI_BUNDLE;27      this.args.app = null;28    } else {29      // make sure args.app has something in it so we get to the right spots30      // in moveBuiltInApp()31      this.args.app = "safari";32    }33    cb();34  }35};36Safari.prototype.moveBuiltInApp = function (cb) {37  if (!this.args.udid && this.args.app !== null) {38    logger.debug("Trying to use mobile safari, version " +39                 this.args.platformVersion);40    this.sim.prepareSafari(this.args.tmpDir, function (err, attemptedApp, origApp) {41      if (err) {42        logger.error("Could not prepare mobile safari: " + err);43        return cb(err);44      }45      logger.debug("Using mobile safari app at " + attemptedApp);46      this.args.app = attemptedApp;47      this.args.origAppPath = origApp;48      cb();49    }.bind(this));50  } else {51    cb();52  }53};54Safari.prototype._start = IOS.prototype.start;55Safari.prototype.start = function (cb, onDie) {56  var newOnDie = function (err) {57    if (this.args.udid) {58      return; // if we're using SafariLauncher, don't report failure59    }60    onDie(err);61  }.bind(this);62  this._start(function (err) {63    if (err) return cb(err);64    this.navToInitialWebview(cb);65  }.bind(this), newOnDie);66};67Safari.prototype.shouldIgnoreInstrumentsExit = function () {68  return !!this.args.udid &&69         this.iOSSDKVersion < NATIVE_REAL_SAFARI_MIN_VER;70};71Safari.prototype._click = IOS.prototype.click;72Safari.prototype.click = function (elementId, cb) {73  if (this.capabilities.nativeWebTap && !this.args.udid) {74    // atoms-based clicks don't always work in safari 775    this.nativeWebTap(elementId, cb);76  } else {77    this._click(elementId, cb);78  }79};80Safari.prototype.setBundleId = function (cb) {81  this.args.bundleId = SAFARI_BUNDLE;82  cb();83};84Safari.prototype._setInitialOrientation = IOS.prototype.setInitialOrientation;85Safari.prototype.setInitialOrientation = function (cb) {86  if (this.shouldIgnoreInstrumentsExit()) {87    logger.debug("Not setting initial orientation because we're on " +88                 "SafariLauncher");89    return cb();90  }91  this._setInitialOrientation(cb);92};93Safari.prototype._configureBootstrap = IOS.prototype.configureBootstrap;94Safari.prototype.configureBootstrap = function (cb) {95  if (this.shouldIgnoreInstrumentsExit()) {96    logger.debug("Not setting bootstrap config because we're on " +97                 "SafariLauncher");98    return cb();99  }100  this._configureBootstrap(cb);101};102Safari.prototype.installToRealDevice = function (cb) {103  if (this.args.udid) {104    try {105      if (!this.realDevice) {106        this.realDevice = this.getIDeviceObj();107      }108    } catch (e) {109      return cb(e);110    }111    this.isAppInstalled("com.bytearc.SafariLauncher", function (err, installed) {112      if (err || !installed) {113        this.installApp(this.args.app, cb);114      } else {115        cb();116      }117    }.bind(this));118  } else {119    logger.debug("Not installing to real device since we're on sim");120    cb();121  }122};123Safari.prototype.clearAppData = function (cb) {124  if (this.args.fullReset) {125    // Even though we delete typical apps on a regular reset, we do a good126    // job of getting safari back to its original state, so actually deleting127    // it is overkill in most cases, and requires an instantLaunchAndQuit.128    // So we only delete it if the user requests a full reset129    try {130      this.sim.deleteSafari();131    } catch (e) {132      return cb(e);133    }134    cb();135  } else {136    this.sim.cleanSafari(this.keepAppToRetainPrefs, cb);137  }138};139Safari.prototype._stopRemote = IOS.prototype.stopRemote;140Safari.prototype.stopRemote = function () {141  this._stopRemote(true);142};143Safari.prototype._stop = IOS.prototype.stop;144Safari.prototype.stop = function (cb) {145  if (this.shouldIgnoreInstrumentsExit()) {146    logger.debug("Stopping safariLauncher");147    this.shutdown(null, cb);148  } else {149    this._stop(cb);150  }151};...

Full Screen

Full Screen

real-device-management.js

Source:real-device-management.js Github

copy

Full Screen

1import { utilities } from 'appium-ios-device';2import IOSDeploy from './ios-deploy';3import log from './logger';4async function getConnectedDevices () {5  return await utilities.getConnectedDevices();6}7async function getOSVersion (udid) {8  return await utilities.getOSVersion(udid);9}10async function resetRealDevice (device, opts) {11  if (!opts.bundleId || !opts.fullReset) {12    return;13  }14  let bundleId = opts.bundleId;15  log.debug(`Reset: fullReset requested. Will try to uninstall the app '${bundleId}'.`);16  if (!await device.isAppInstalled(bundleId)) {17    log.debug('Reset: app not installed. No need to uninstall');18    return;19  }20  try {21    await device.remove(bundleId);22  } catch (err) {23    log.error(`Reset: could not remove '${bundleId}' from device: ${err.message}`);24    throw err;25  }26  log.debug(`Reset: removed '${bundleId}'`);27}28async function runRealDeviceReset (device, opts) {29  if (!opts.noReset || opts.fullReset) {30    log.debug('Reset: running ios real device reset flow');31    if (!opts.noReset) {32      await resetRealDevice(device, opts);33    }34  } else {35    log.debug('Reset: fullReset not set. Leaving as is');36  }37}38async function installToRealDevice (device, app, bundleId, noReset = true) {39  if (!device.udid || !app) {40    log.debug('No device id or app, not installing to real device.');41    return;42  }43  if (await device.isAppInstalled(bundleId)) {44    if (noReset) {45      log.debug(`App '${bundleId}' is already installed. No need to reinstall.`);46      return;47    }48    log.debug(`Reset requested. Removing app with id '${bundleId}' from the device`);49    await device.remove(bundleId);50  }51  log.debug(`Installing '${app}' on device with UUID '${device.udid}'...`);52  await device.install(app);53  log.debug('The app has been installed successfully.');54}55function getRealDeviceObj (udid) {56  log.debug(`Creating iDevice object with udid '${udid}'`);57  return new IOSDeploy(udid);58}59export { getConnectedDevices, getOSVersion, runRealDeviceReset, installToRealDevice,...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var driver = new webdriver.Builder()3    .withCapabilities({4    })5    .build();6driver.installToRealDevice('

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  .init()7  .then(function() {8    return driver.execute('mobile: installToRealDevice', {'ipaPath': '/path/to/ipa/file'});9  })10  .then(function() {11    console.log('App installed successfully!');12  })13  .quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const XCUITestDriver = require('appium-xcuitest-driver');3const driver = wd.promiseChainRemote('localhost', 4723);4const desiredCaps = {5};6driver.init(desiredCaps)7  .then(() => {8    return driver.installToRealDevice('/Users/sravanthi/Desktop/MyApp.app');9  })10  .then(() => {11    console.log('App successfully installed on real device');12  })13  .catch((err) => {14    console.log('Error occured while installing app on real device: ', err);15  });16    at ChildProcess.proc.on.code (/Applications/Appium.app/Contents/Resources/app/node_modules/appium-xcuitest-driver/node_modules/node-teen_process/lib/exec.js:94:19)17    at ChildProcess.emit (events.js:182:13)

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const { installToRealDevice } = require('appium-xcuitest-driver');3const { exec } = require('teen_process');4const run = async () => {5  const opts = {6  };7  const driver = wd.promiseChainRemote({8  });9  await driver.init(opts);10  await driver.sleep(2000);11  await installToRealDevice(opts, driver);12  await exec('idevicediagnostics', ['restart']);13  await driver.quit();14};15run();16const wd = require('wd');17const { installToRealDevice } = require('appium-xcuitest-driver');18const { exec } = require('teen_process');19const run = async () => {20  const opts = {21  };22  const driver = wd.promiseChainRemote({23  });24  await driver.init(opts);25  await driver.sleep(2000);26  await installToRealDevice(opts, driver);27  await exec('idevicediagnostics', ['restart']);28  await driver.quit();29};30run();31const wd = require('wd');32const { installToRealDevice } = require('appium-xcuitest-driver');33const { exec } = require('teen_process');34const run = async () => {35  const opts = {

Full Screen

Using AI Code Generation

copy

Full Screen

1const wdio = require('webdriverio');2const opts = {3  capabilities: {4  }5};6async function main() {7  const driver = await wdio.remote(opts);8  await driver.installToRealDevice('/path/to/app.ipa');9  await driver.deleteSession();10}11main();

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const path = require('path');3const fs = require('fs');4const app = path.resolve(__dirname, 'SampleApp.app');5const appium = require('appium');6const {exec} = require('child_process');7const driver = wd.promiseChainRemote('localhost', 4723);8const caps = {9};10async function installToRealDevice() {11  const appPath = caps.app;12  const bundleId = caps.bundleId;13  const deviceName = caps.deviceName;14  const platformVersion = caps.platformVersion;15  const ipaName = appPath.split('/').pop();16  const ipaPath = appPath.replace(ipaName, '');17  const ipaPathInDevice = `/var/mobile/Containers/Data/Application/${bundleId}`;18  const ipaPathInDeviceWithAppName = `${ipaPathInDevice}/${ipaName}`;19  const command = `ideviceinstaller -u ${deviceName} -i ${ipaPath}${ipaName}`;20  const commandForUninstall = `ideviceinstaller -u ${deviceName} -U ${bundleId}`;21  const commandForCheck = `ideviceinstaller -u ${deviceName} -l`;22  const commandForCheckAppPath = `ideviceinstaller -u ${deviceName} -o ${bundleId}`;23  const commandForCheckAppPathInDevice = `ssh root@${deviceName} ls ${ipaPathInDevice}`;24  const commandForCheckAppPathInDeviceWithAppName = `ssh root@${deviceName} ls ${ipaPathInDeviceWithAppName}`;25  const commandForCheckAppPathInDeviceWithAppNameWithVersion = `ssh root@${deviceName} ls ${ipaPathInDeviceWithAppName}/Versions`;26  const commandForCheckAppPathInDeviceWithAppNameWithVersionWithCurrent = `ssh root@${deviceName} ls ${ipaPathInDeviceWithAppName}/Versions/Current`;27  const commandForCheckAppPathInDeviceWithAppNameWithVersionWithCurrentWithResources = `ssh root@${deviceName} ls ${ipaPathInDeviceWithAppName}/Versions/Current/Resources`;

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