How to use services.startInstallationProxyService method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

file-movement.js

Source:file-movement.js Github

copy

Full Screen

...321 *                          'UIFileSharingEnabled' attribute.322 *                          Only user apps might have it.323 */324async function getAvailableBundleIds (udid) {325  const service = await services.startInstallationProxyService(udid);326  try {327    const applications = await service.listApplications({applicationType: 'User'});328    const bundleIds = [];329    for (const [key, value] of Object.entries(applications)) {330      if (!value.UIFileSharingEnabled) {331        continue;332      }333      bundleIds.push(key);334    }335    return bundleIds;336  } finally {337    service.close();338  }339}...

Full Screen

Full Screen

app-management.js

Source:app-management.js Github

copy

Full Screen

...75  const {bundleId} = requireOptions(opts, ['bundleId']);76  let instrumentService;77  let installProxyService;78  try {79    installProxyService = await services.startInstallationProxyService(this.opts.device.udid);80    const apps = await installProxyService.listApplications();81    if (!apps[bundleId]) {82      this.log.info(`The bundle id '${bundleId}' did not exist`);83      return false;84    }85    const executableName = apps[bundleId].CFBundleExecutable;86    this.log.debug(`The executable name for the bundle id '${bundleId}' was '${executableName}'`);87    instrumentService = await services.startInstrumentService(this.opts.device.udid);88    const processes = await instrumentService.callChannel(INSTRUMENT_CHANNEL.DEVICE_INFO, 'runningProcesses');89    const process = processes.selector.find((process) => process.name === executableName);90    if (!process) {91      this.log.info(`The process of the bundle id '${bundleId}' was not running`);92      return false;93    }94    await instrumentService.callChannel(INSTRUMENT_CHANNEL.PROCESS_CONTROL, 'killPid:', `${process.pid}`);95    return true;96  } catch (err) {97    this.log.warn(`Failed to kill '${bundleId}'. Original error: ${err.stderr || err.message}`);98    return false;99  } finally {100    if (installProxyService) {101      installProxyService.close();102    }103    if (instrumentService) {104      instrumentService.close();105    }106  }107};108/**109 * Returns the current application state110 *111 * @param {Object} opts - Options set, which must contain `bundleId` property112 * @returns {number} The actual application state code. See113 * https://developer.apple.com/documentation/xctest/xcuiapplicationstate?language=objc114 * to get the list of possible values.115 */116commands.mobileQueryAppState = async function mobileQueryAppState (opts = {}) {117  return await this.proxyCommand('/wda/apps/state', 'POST', requireOptions(opts, ['bundleId']));118};119commands.installApp = async function installApp (appPath, opts = {}) {120  await this.mobileInstallApp({121    ...(_.isPlainObject(opts) ? opts : {}),122    app: appPath,123  });124};125commands.activateApp = async function activateApp (bundleId, opts = {}) {126  return await this.mobileLaunchApp(Object.assign({}, opts, {bundleId}));127};128commands.isAppInstalled = async function isAppInstalled (bundleId) {129  return await this.mobileIsAppInstalled({bundleId});130};131commands.terminateApp = async function terminateApp (bundleId) {132  return await this.mobileTerminateApp({bundleId});133};134commands.queryAppState = async function queryAppState (bundleId) {135  return await this.mobileQueryAppState({bundleId});136};137/**138 * @typedef {Object} ListAppsOptions139 * @property {'System'|'User'} applicationType [User] The type of applications to list140 */141/**142 * List applications installed on the real device under test143 *144 * @param {ListAppsOptions} opts145 * @returns {Array<Object>} A list of apps, where each item is a map where keys are146 * bundle identifiers and values are maps of platform-specific app properties.147 */148commands.mobileListApps = async function mobileListApps (opts = {}) {149  if (!this.isRealDevice()) {150    throw new errors.NotImplementedError(`This extension is only supported on real devices`);151  }152  const {153    applicationType = 'User',154  } = opts;155  const service = await services.startInstallationProxyService(this.opts.device.udid);156  try {157    return await service.listApplications({applicationType});158  } finally {159    service.close();160  }161};...

Full Screen

Full Screen

ios-deploy.js

Source:ios-deploy.js Github

copy

Full Screen

...15  constructor (udid) {16    this.udid = udid;17  }18  async remove (bundleid) {19    const service = await services.startInstallationProxyService(this.udid);20    try {21      await service.uninstallApplication(bundleid);22    } finally {23      service.close();24    }25  }26  async removeApp (bundleId) {27    await this.remove(bundleId);28  }29  async install (app, timeout) {30    const timer = new timing.Timer().start();31    try {32      const bundlePathOnPhone = await this.pushAppBundle(app, timeout);33      await this.installApplication(bundlePathOnPhone);34    } catch (err) {35      log.warn(`Error installing app: ${err.message}`);36      log.warn(`Falling back to '${IOS_DEPLOY}' usage`);37      try {38        await fs.which(IOS_DEPLOY);39      } catch (err1) {40        throw new Error(`Could not install '${app}':\n` +41          `  - ${err.message}\n` +42          `  - '${IOS_DEPLOY}' utility has not been found in PATH. Is it installed?`);43      }44      try {45        await exec(IOS_DEPLOY, [46          '--id', this.udid,47          '--bundle', app,48        ]);49      } catch (err1) {50        throw new Error(`Could not install '${app}':\n` +51          `  - ${err.message}\n` +52          `  - ${err1.stderr || err1.stdout || err1.message}`);53      }54    }55    log.info(`App installation succeeded after ${timer.getDuration().asMilliSeconds.toFixed(0)}ms`);56  }57  async installApplication (bundlePathOnPhone) {58    const notificationService = await services.startNotificationProxyService(this.udid);59    const installationService = await services.startInstallationProxyService(this.udid);60    const appInstalledNotification = new B((resolve) => {61      notificationService.observeNotification(APPLICATION_INSTALLED_NOTIFICATION, {notification: resolve});62    });63    try {64      await installationService.installApplication(bundlePathOnPhone, {PackageType: 'Developer'});65      try {66        await appInstalledNotification.timeout(APPLICATION_NOTIFICATION_TIMEOUT, `Could not get the application installed notification within ${APPLICATION_NOTIFICATION_TIMEOUT}ms but we will continue`);67      } catch (e) {68        log.warn(`Failed to receive the notification. Error: ${e.message}`);69      }70    } finally {71      installationService.close();72      notificationService.close();73    }74  }75  async pushAppBundle (app, timeout = DEFAULT_ITEM_PUSH_TIMEOUT) {76    const timer = new timing.Timer().start();77    const afcService = await services.startAfcService(this.udid);78    // We are pushing serially due to this https://github.com/appium/appium/issues/13115. There is nothing else we can do besides this79    try {80      const bundlePathOnPhone = await this.createAppPath(afcService, app);81      await fs.walkDir(app, true, async (itemPath, isDir) => {82        const pathOnPhone = path.join(bundlePathOnPhone, path.relative(app, itemPath));83        if (isDir) {84          await afcService.createDirectory(pathOnPhone);85        } else {86          const readStream = fs.createReadStream(itemPath, {autoClose: true});87          const writeStream = await afcService.createWriteStream(pathOnPhone, {autoDestroy: true});88          writeStream.on('finish', writeStream.destroy);89          let pushError = null;90          const itemPushWait = new B((resolve, reject) => {91            writeStream.on('close', () => {92              if (pushError) {93                reject(pushError);94              } else {95                resolve();96              }97            });98            const onStreamError = (e) => {99              readStream.unpipe(writeStream);100              log.debug(e);101              pushError = e;102            };103            writeStream.on('error', onStreamError);104            readStream.on('error', onStreamError);105          });106          readStream.pipe(writeStream);107          await itemPushWait.timeout(timeout,108            `Could not push '${itemPath}' within the timeout of ${timeout}ms. ` +109            `Consider increasing the value of 'appPushTimeout' capability.`);110        }111      });112      log.debug(`Pushed the app files successfully after ${timer.getDuration().asMilliSeconds.toFixed(0)}ms`);113      return bundlePathOnPhone;114    } finally {115      afcService.close();116    }117  }118  async createAppPath (afcService, localAppPath) {119    const basename = path.basename(localAppPath);120    const relativePath = path.join(INSTALLATION_STAGING_DIR, basename);121    try {122      await afcService.deleteDirectory(relativePath);123    } catch (ign) {}124    await afcService.createDirectory(relativePath);125    return relativePath;126  }127  async installApp (app, timeout) {128    await this.install(app, timeout);129  }130  /**131   * Return an application object if test app has 'bundleid'.132   * The target bundleid can be User and System apps.133   * @param {string} bundleid The bundleId to ensure it is installed134   * @return {boolean} Returns True if the bundleid exists in the result of 'listApplications' like:135   * { "com.apple.Preferences":{136   *   "UIRequiredDeviceCapabilities":["arm64"],137   *   "UIRequiresFullScreen":true,138   *   "CFBundleInfoDictionaryVersion":"6.0",139   *   "Entitlements":140   *     {"com.apple.frontboard.delete-application-snapshots":true,..141   */142  async isAppInstalled (bundleid) {143    const service = await services.startInstallationProxyService(this.udid);144    try {145      const applications = await service.lookupApplications({ bundleIds: bundleid });146      return !!applications[bundleid];147    } finally {148      service.close();149    }150  }151  /**152   * @param {string} bundleName The name of CFBundleName in Info.plist153   *154   * @returns {Array<string>} A list of User level apps' bundle ids which has155   *                          'CFBundleName' attribute as 'bundleName'.156   */157  async getUserInstalledBundleIdsByBundleName (bundleName) {158    const service = await services.startInstallationProxyService(this.udid);159    try {160      const applications = await service.listApplications({applicationType: 'User'});161      return _.reduce(applications, (acc, {CFBundleName}, key) => {162        if (CFBundleName === bundleName) {163          acc.push(key);164        }165        return acc;166      }, []);167    } finally {168      service.close();169    }170  }171  async getPlatformVersion () {172    return await utilities.getOSVersion(this.udid);...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const wdio = require('webdriverio');2const opts = {3  capabilities: {4  }5};6async function main () {7  const client = await wdio.remote(opts);8  await client.startInstallationProxyService();9  await client.installApp('path to app');10  await client.removeApp('bundle id');11  await client.stopInstallationProxyService();12  await client.deleteSession();13}14main();15const wdio = require('webdriverio');16const opts = {17  capabilities: {18  }19};20async function main () {21  const client = await wdio.remote(opts);22  await client.startWDA();23  await client.installApp('path to app');24  await client.removeApp('bundle id');25  await client.stopWDA();26  await client.deleteSession();27}28main();29const wdio = require('webdriverio');30const opts = {31  capabilities: {32  }33};34async function main () {35  const client = await wdio.remote(opts);36  await client.startWDA();37  await client.startInstallationProxyService();38  await client.installApp('path to app');39  await client.removeApp('bundle id');40  await client.stopInstallationProxyService();41  await client.stopWDA();42  await client.deleteSession();43}44main();45const wdio = require('webdriverio');46const opts = {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { services } = require('appium-xcuitest-driver');2const { startInstallationProxyService } = services;3(async () => {4  const installationProxy = await startInstallationProxyService();5  console.log(installationProxy);6})();7const { services } = require('appium-xcuitest-driver');8const { startWdaSession } = services;9(async () => {10  console.log(wda);11})();

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const assert = require('assert');3const fs = require('fs');4const path = require('path');5const { spawn } = require('child_process');6const { exec } = require('child_process');7const { ex

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var fs = require('fs');4var os = require('os');5var path = require('path');6var rimraf = require('rimraf');7var app = path.resolve(__dirname, 'UICatalog.app.zip');8var appDir = path.resolve(os.tmpdir(), 'UICatalog.app');9var testApp = path.resolve(appDir, 'UICatalog.app');10var desired = {11};12var driver = wd.promiseChainRemote('localhost', 4723);13driver.on('status', function(info) {14  console.log(info);15});16driver.on('command', function(meth, path, data) {17  console.log(' > ' + meth, path, data || '');18});19driver.on('http', function(meth, path, data) {20  console.log(' > ' + meth, path, data || '');21});22  .init(desired)23  .then(function() { return driver.waitForElementByAccessibilityId('UICatalog', 10000); })24  .then(function(el) { return el.click(); })25  .then(function() { return driver.waitForElementByAccessibilityId('Action Sheets', 10000); })26  .then(function(el) { return el.click(); })27  .then(function() { return driver.waitForElementByAccessibilityId('Okay / Cancel', 10000); })28  .then(function(el) { return el.click(); })29  .then(function() { return driver.waitForElementByAccessibilityId('Okay', 10000); })30  .then(function(el) { return el.click(); })31  .then(function() {32      .elementByAccessibilityId('Okay')33      .should.eventually.exist;34  })35  .fin(function() { return driver.quit(); })36  .done();37var wd = require('wd');38var assert = require('assert');39var fs = require('fs');40var os = require('os');41var path = require('path');42var rimraf = require('rimraf');43var app = path.resolve(__dirname, 'UICatalog.app.zip');

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var path = require('path');4var fs = require('fs');5var os = require('os');6var xcode = require('appium-xcode');7var xcodebuild = require('appium-xcode').xcodebuild;8var simctl = require('appium-ios-simulator').simctl;9var utils = require('appium-ios-simulator').utils;10var uuid = require('node-uuid');11var mkdirp = require('mkdirp');12var rimraf = require('rimraf');13var _ = require('lodash');14var logger = require('appium-logger').get('appium');15var async = require('async');16var shell = require('shelljs');17var desired = {

Full Screen

Using AI Code Generation

copy

Full Screen

1var appium = require('appium-xcuitest-driver');2var path = require('path');3var fs = require('fs');4var _ = require('lodash');5var logger = require('winston');6var request = require('request');7var async = require('async');8var plist = require('plist');9var exec = require('child_process').exec;10var mkdirp = require('mkdirp');11var rimraf = require('rimraf');12var appiumPath = path.resolve(__dirname, '../appium-xcuitest-driver');13var appiumPkg = require(appiumPath + '/package.json');14var serverPath = path.resolve(appiumPath, appiumPkg.main);15var server = require(serverPath);16var serverArgs = {

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var _ = require('lodash');3var assert = require('assert');4var fs = require('fs');5var path = require('path');6var portfinder = require('portfinder');7var rimraf = require('rimraf');8var xcode = require('appium-xcode');9var B = require('bluebird');10var { logger } = require('appium-support');11var log = logger.getLogger('Appium');12var TEST_APP = path.resolve(__dirname, '..', '..', 'test', 'assets', 'TestApp.zip');13var TEST_APP_PKG = 'io.appium.TestApp';14var TEST_APP_BUNDLE_ID = 'io.appium.TestApp';15var CAPS = {16};17async function main () {18  let port = await startInstallationProxyService();19  let iproxy = await getInstallationProxyClient(port);20  let bundleId = await iproxy.lookupApplication({ bundleId: TEST_APP_BUNDLE_ID });21  assert.equal(bundleId, TEST_APP_BUNDLE_ID);22  await iproxy.installApplication({ appPath: TEST_APP });23  bundleId = await iproxy.lookupApplication({ bundleId: TEST_APP_BUNDLE_ID });24  assert.equal(bundleId, TEST_APP_BUNDLE_ID);25  await iproxy.uninstallApplication({ bundleId: TEST_APP_BUNDLE_ID });

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