How to use appIsPackageOrBundle method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

driver.js

Source:driver.js Github

copy

Full Screen

...320 function appIsPackageOrBundle (app) {321 return (/^([a-zA-Z0-9\-_]+\.[a-zA-Z0-9\-_]+)+$/).test(app);322 }323 // the app name is a bundleId assign it to the bundleId property324 if (!this.opts.bundleId && appIsPackageOrBundle(this.opts.app)) {325 this.opts.bundleId = this.opts.app;326 this.opts.app = '';327 }328 // we have a bundle ID, but no app, or app is also a bundle329 if ((this.opts.bundleId && appIsPackageOrBundle(this.opts.bundleId)) &&330 (this.opts.app === '' || appIsPackageOrBundle(this.opts.app))) {331 log.debug('App is an iOS bundle, will attempt to run as pre-existing');332 return;333 }334 // check for supported build-in apps335 if (this.opts.app && this.opts.app.toLowerCase() === 'settings') {336 this.opts.bundleId = 'com.apple.Preferences';337 this.opts.app = null;338 return;339 } else if (this.opts.app && this.opts.app.toLowerCase() === 'calendar') {340 this.opts.bundleId = 'com.apple.mobilecal';341 this.opts.app = null;342 return;343 }344 try {...

Full Screen

Full Screen

device.js

Source:device.js Github

copy

Full Screen

1"use strict";2var fs = require('fs')3 , path = require('path')4 , _ = require('underscore')5 , logger = require('../server/logger.js').get('appium')6 , helpers = require('../helpers.js')7 , isWindows = require('appium-support').system.isWindows8 , copyLocalZip = helpers.copyLocalZip9 , unzipApp = helpers.unzipApp10 , downloadFile = helpers.downloadFile11 , capConversion = require('../server/capabilities.js').capabilityConversions12 , DeviceSettings = require('./device-settings.js')13 , url = require('url');14var Device = function () {15 throw new Error("Cannot instantiate Device directly");16};17Device.prototype.init = function () {18 this.appExt = null;19 this.tempFiles = [];20 this.args = {};21 this.capabilities = {};22 this.settings = new DeviceSettings();23};24Device.prototype.configure = function (args, caps) {25 _.extend(this.args, args);26 _.extend(this.capabilities, caps);27 _.each(caps, function (val, cap) {28 this.setArgFromCap(cap, cap);29 }.bind(this));30 if (this.args.tmpDir === null) {31 // use a custom tmp dir to avoid loosing data and app32 // when computer is restarted33 this.args.tmpDir = process.env.APPIUM_TMP_DIR ||34 (isWindows() ? process.env.TEMP : "/tmp");35 }36 if (this.args.traceDir === null) {37 this.args.traceDir = path.resolve(this.args.tmpDir , 'appium-instruments');38 }39};40Device.prototype.setArgFromCap = function (arg, cap) {41 if (typeof this.capabilities[cap] !== "undefined") {42 if (_.has(capConversion, cap)) {43 var key = capConversion[cap];44 if (!_.has(this.capabilities, key)) {45 // if we have both 'version' and 'platformVersion' caps being sent,46 // make sure 'platformVersion' isn't overwritten by 'version'47 this.args[key] = this.capabilities[cap];48 }49 } else {50 this.args[arg] = this.capabilities[cap];51 }52 }53};54Device.prototype.appString = function () {55 return this.args.app ? this.args.app.toString() : '';56};57Device.prototype.configureApp = function (cb) {58 if (this.args.app.substring(0, 4).toLowerCase() === "http") {59 this.configureDownloadedApp(cb);60 } else {61 this.configureLocalApp(cb);62 }63};64Device.prototype.configureLocalApp = function (cb) {65 this.args.app = path.resolve(this.args.app);66 var appPath = this.args.app;67 var origin = this.capabilities.app ? "desired caps" : "command line";68 var ext = appPath.substring(appPath.length - 4).toLowerCase();69 if (ext === this.appExt) {70 this.args.app = appPath;71 logger.debug("Using local app from " + origin + ": " + appPath);72 fs.stat(appPath, function (err) {73 if (err) {74 return cb(new Error("Error locating the app: " + err.message));75 }76 cb();77 });78 } else if (ext === ".zip" || ext === ".ipa") {79 logger.debug("Using local " + ext + " from " + origin + ": " + appPath);80 this.unzipLocalApp(appPath, function (zipErr, newAppPath) {81 if (zipErr) return cb(zipErr);82 if (ext === ".ipa") {83 this.args.ipa = this.args.app;84 }85 this.args.app = newAppPath;86 logger.debug("Using locally extracted app: " + this.args.app);87 cb();88 }.bind(this));89 } else {90 var msg = "Using local app, but didn't end in .zip, .ipa or " + this.appExt;91 logger.error(msg);92 cb(new Error(msg));93 }94};95Device.prototype.appIsPackageOrBundle = function (app) {96 return (/^([a-zA-Z0-9\-_]+\.[a-zA-Z0-9\-_]+)+$/).test(app);97};98Device.prototype.configureDownloadedApp = function (cb) {99 var origin = this.capabilities.app ? "desired caps" : "command line";100 var appUrl;101 try {102 appUrl = url.parse(this.args.app);103 } catch (err) {104 cb("Invalid App URL (" + this.args.app + ")");105 }106 var ext = path.extname(appUrl.pathname);107 if (ext === ".apk") {108 try {109 downloadFile(url.format(appUrl), ".apk", function (appPath) {110 this.tempFiles.push(appPath);111 this.args.app = appPath;112 cb();113 }.bind(this));114 } catch (e) {115 var err = e.toString();116 logger.error("Failed downloading app from appUrl " + appUrl.href);117 cb(err);118 }119 } else if (ext === ".zip" || ext === ".ipa") {120 try {121 this.downloadAndUnzipApp(url.format(appUrl), function (zipErr, appPath) {122 if (zipErr) {123 cb(zipErr);124 } else {125 this.args.app = appPath;126 logger.debug("Using extracted app: " + this.args.app);127 cb();128 }129 }.bind(this));130 logger.debug("Using downloadable app from " + origin + ": " + appUrl.href);131 } catch (e) {132 var err = e.toString();133 logger.error("Failed downloading app from appUrl " + appUrl.href);134 cb(err);135 }136 } else {137 cb("App URL (" + this.args.app + ") didn't seem to point to a .zip, " +138 ".apk, or .ipa file");139 }140};141Device.prototype.unzipLocalApp = function (localZipPath, cb) {142 try {143 copyLocalZip(localZipPath, function (err, zipPath) {144 if (err) return cb(err);145 this.unzipApp(zipPath, cb);146 }.bind(this));147 } catch (e) {148 logger.error("Failed copying and unzipping local app: " + localZipPath);149 cb(e);150 }151};152Device.prototype.unzipApp = function (zipPath, cb) {153 this.tempFiles.push(zipPath);154 unzipApp(zipPath, this.appExt, function (err, appPath) {155 if (err) {156 cb(err, null);157 } else {158 this.tempFiles.push(appPath);159 cb(null, appPath);160 }161 }.bind(this));162};163Device.prototype.downloadAndUnzipApp = function (appUrl, cb) {164 downloadFile(appUrl, ".zip", function (zipPath) {165 this.unzipApp(zipPath, cb);166 }.bind(this));167};168// get a specific setting169Device.prototype.getSetting = function (str) {170 return this.settings._settings[str];171};...

Full Screen

Full Screen

utils.js

Source:utils.js Github

copy

Full Screen

1import { fs, plist } from 'appium-support';2import logger from './logger';3import path from 'path';4import _ from 'lodash';5import { exec } from 'teen_process';6const rootDir = path.resolve(__dirname, '..', '..');7function appIsPackageOrBundle (app) {8 return (/^([a-zA-Z0-9\-_]+\.[a-zA-Z0-9\-_]+)+$/).test(app);9}10async function removeInstrumentsSocket (sock) {11 logger.debug("Removing any remaining instruments sockets");12 await fs.rimraf(sock);13 logger.debug("Cleaned up instruments socket " + sock);14}15function getSimForDeviceString (dString, availDevices) {16 let matchedDevice = null;17 let matchedUdid = null;18 _.each(availDevices, function (device) {19 if (device.indexOf(dString) !== -1) {20 matchedDevice = device;21 try {22 matchedUdid = /.+\[([^\]]+)\]/.exec(device)[1];23 } catch (e) {24 matchedUdid = null;25 }26 }27 });28 return [matchedDevice, matchedUdid];29}30async function detectUdid (caps) {31 if (caps.udid !== null && caps.udid === "auto") {32 logger.debug("Auto-detecting iOS udid...");33 let cmd, args = [];34 try {35 cmd = await fs.which('idevice_id');36 args.push('-l');37 } catch (err) {38 cmd = require.resolve('udidetect');39 }40 let udid;41 try {42 let {stdout} = await exec(cmd, args, {timeout: 3000});43 udid = stdout.split("\n")[0];44 } catch (err) {45 logger.error("Error detecting udid");46 throw err;47 }48 if (udid && udid.length > 2) {49 caps.udid = udid;50 logger.debug("Detected udid as " + caps.udid);51 } else {52 throw new Error("Could not detect udid.");53 }54 } else {55 logger.debug("Not auto-detecting udid.");56 }57}58async function parseLocalizableStrings (opts) {59 if (_.isNull(opts.app) || _.isUndefined(opts.app)) {60 logger.debug("Localizable.strings is not currently supported when using real devices.");61 return;62 }63 let language = opts.language;64 let stringFile = "Localizable.strings";65 let strings = null;66 if (language) {67 strings = path.resolve(opts.app, language + ".lproj", stringFile);68 }69 if (!await fs.exists(strings)) {70 if (language) {71 logger.debug("No strings file '" + stringFile + "' for language '" + language + "', getting default strings");72 }73 strings = path.resolve(opts.app, stringFile);74 }75 if (!await fs.exists(strings)) {76 strings = path.resolve(opts.app, opts.localizableStringsDir, stringFile);77 }78 if (!await fs.exists(strings)) {79 logger.warn('Could not file localizable strings file: Localizable.strings!');80 return;81 }82 let obj;83 try {84 obj = await plist.parsePlistFile(strings);85 logger.debug("Parsed app " + stringFile);86 opts.localizableStrings = obj;87 } catch (err) {88 logger.warn("Could not parse app " + stringFile +" assuming it " +89 "doesn't exist");90 }91}92function shouldPrelaunchSimulator (caps, iosSdkVersion) {93 let shouldPrelaunch = false;94 if (caps.defaultDevice || iosSdkVersion >= 7.1) {95 if (this.iosSdkVersion >= 7.1) {96 logger.debug("We're on iOS7.1+ so forcing defaultDevice on");97 } else {98 logger.debug("User specified default device, letting instruments launch it");99 }100 } else {101 shouldPrelaunch = true;102 }103 return shouldPrelaunch;104}105async function setDeviceTypeInInfoPlist (app, deviceString) {106 if (_.isNull(app) || _.isUndefined(app)) { return; }107 let plistFile = path.resolve(app, "Info.plist");108 let isiPhone = deviceString.toLowerCase().indexOf("ipad") === -1;109 let deviceTypeCode = isiPhone ? 1 : 2;110 await plist.updatePlistFile(plistFile, {UIDeviceFamily: [deviceTypeCode]});111}112function unwrapEl (el) {113 if(typeof el === 'object' && el.ELEMENT){114 return el.ELEMENT;115 }116 return el;117}118export default { rootDir, removeInstrumentsSocket,119 appIsPackageOrBundle, detectUdid, parseLocalizableStrings,120 shouldPrelaunchSimulator, setDeviceTypeInInfoPlist, getSimForDeviceString,...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { AppiumDriver } = require('appium-base-driver');2const { XCUITestDriver } = require('appium-xcuitest-driver');3const { appIsPackageOrBundle } = XCUITestDriver.prototype.helpers;4const app = 'com.example.Example';5const appIsPackageOrBundle = appIsPackageOrBundle(app);6const { AppiumDriver } = require('appium-base-driver');7const { XCUITestDriver } = require('appium-xcuitest-driver');8const { appIsPackageOrBundle } = XCUITestDriver.prototype.helpers;9const app = 'com.example.Example';10const appIsPackageOrBundle = appIsPackageOrBundle(app);

Full Screen

Using AI Code Generation

copy

Full Screen

1var appPath = "/Users/username/Desktop/MyApp.app";2var isPackage = await driver.appIsPackageOrBundle(appPath);3console.log(isPackage);4appInstall()5appUninstall()6appTerminate()7appActivate()8appReset()9appStrings()10appBackground()11appClose()12appGetState()13appGetAttributes()14appGetLogTypes()15appGetLog()16appGetPerformanceData()17appGetPerformanceDataTypes()

Full Screen

Using AI Code Generation

copy

Full Screen

1const XCUITestDriver = require('appium-xcuitest-driver');2const APP_PATH = '/path/to/my.app';3const BUNDLE_ID = 'com.my.app';4const isPackage = XCUITestDriver.appIsPackageOrBundle(APP_PATH, BUNDLE_ID);5console.log(isPackage);6const XCUITestDriver = require('appium-xcuitest-driver');7const APP_PATH = '/path/to/my.app';8const BUNDLE_ID = 'com.my.app';9const appInfo = XCUITestDriver.appInfo(APP_PATH, BUNDLE_ID);10console.log(appInfo);11const XCUITestDriver = require('appium-xcuitest-driver');12const APP_PATH = '/path/to/my.app';13const BUNDLE_ID = 'com.my.app';14const appInfo = XCUITestDriver.appInfo(APP_PATH, BUNDLE_ID);

Full Screen

Using AI Code Generation

copy

Full Screen

1let appPackage = 'com.apple.mobilesafari';2let appPath = '/Users/username/Desktop/appium-xcuitest-driver/test/functional/testapp.app';3let appBundle = 'com.example.apple-samplecode.UICatalog';4let appIsPackageOrBundle = function(app) {5 return (/^([a-zA-Z0-9\-_]+\.[a-zA-Z0-9\-_]+)+$/).test(app);6};7console.log('appPackage is a package or bundle?', appIsPackageOrBundle(appPackage));8console.log('appPath is a package or bundle?', appIsPackageOrBundle(appPath));9console.log('appBundle is a package or bundle?', appIsPackageOrBundle(appBundle));10let cmd = `xcrun simctl get_app_container booted ${appPackage}`;11let {stdout} = await exec(cmd);12if (stdout) {13 log.debug(`App ${appPackage} is already installed`);14} else {15 log.debug(`App ${appPackage} is not installed. Will try to install`);16 await installApp(appPackage);17}18let cmd = `xcrun simctl get_app_container booted ${appPackage}`;19let {stdout} = await exec(cmd);20if (stdout) {21 log.debug(`App ${appPackage} is already installed`);22} else {23 log.debug(`App ${appPackage} is not installed. Will try to install`);

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