How to use device.removeApp method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

webdriveragent-specs.js

Source:webdriveragent-specs.js Github

copy

Full Screen

1import { WebDriverAgent, BOOTSTRAP_PATH } from '../..';2import * as dependencies from '../../lib/check-dependencies';3import * as utils from '../../lib/utils';4import chai from 'chai';5import chaiAsPromised from 'chai-as-promised';6import path from 'path';7import _ from 'lodash';8import sinon from 'sinon';9import { withMocks } from 'appium-test-support';10import { fs } from 'appium-support';11chai.should();12chai.use(chaiAsPromised);13const fakeConstructorArgs = {14 device: 'some sim',15 platformVersion: '9',16 host: 'me',17 port: '5000',18 realDevice: false19};20const defaultAgentPath = path.resolve(BOOTSTRAP_PATH, 'WebDriverAgent.xcodeproj');21const customBootstrapPath = '/path/to/wda';22const customAgentPath = '/path/to/some/agent/WebDriverAgent.xcodeproj';23const customDerivedDataPath = '/path/to/some/agent/DerivedData/';24describe('Constructor', function () {25 it('should have a default wda agent if not specified', function () {26 let agent = new WebDriverAgent({}, fakeConstructorArgs);27 agent.bootstrapPath.should.eql(BOOTSTRAP_PATH);28 agent.agentPath.should.eql(defaultAgentPath);29 });30 it('should have custom wda bootstrap and default agent if only bootstrap specified', function () {31 let agent = new WebDriverAgent({}, _.defaults({32 bootstrapPath: customBootstrapPath,33 }, fakeConstructorArgs));34 agent.bootstrapPath.should.eql(customBootstrapPath);35 agent.agentPath.should.eql(path.resolve(customBootstrapPath, 'WebDriverAgent.xcodeproj'));36 });37 it('should have custom wda bootstrap and agent if both specified', function () {38 let agent = new WebDriverAgent({}, _.defaults({39 bootstrapPath: customBootstrapPath,40 agentPath: customAgentPath,41 }, fakeConstructorArgs));42 agent.bootstrapPath.should.eql(customBootstrapPath);43 agent.agentPath.should.eql(customAgentPath);44 });45 it('should have custom derivedDataPath if specified', function () {46 let agent = new WebDriverAgent({}, _.defaults({47 derivedDataPath: customDerivedDataPath48 }, fakeConstructorArgs));49 agent.xcodebuild.derivedDataPath.should.eql(customDerivedDataPath);50 });51});52describe('checking for dependencies', function () {53 const wda = new WebDriverAgent('12.1');54 const xcodebuild = wda.xcodebuild;55 describe('#launch', withMocks({wda, fs, dependencies, xcodebuild}, function (mocks) {56 afterEach(function () {57 mocks.verify();58 });59 it('should call checkForDependencies', async function () {60 wda.useXctestrunFile = false;61 wda.usePrebuiltWDA = false;62 wda.derivedDataPath = undefined;63 wda.device = {};64 wda.device.udid = 'udid';65 mocks.wda.expects('setupProxies').once().returns();66 mocks.fs.expects('exists').returns(true);67 mocks.dependencies.expects('checkForDependencies').once().returns(false);68 mocks.xcodebuild.expects('init').once().returns();69 mocks.xcodebuild.expects('start').once().returns();70 await wda.launch();71 });72 it('should call checkForDependencies since only usePrebuiltWDA', async function () {73 wda.useXctestrunFile = false;74 wda.usePrebuiltWDA = true;75 wda.derivedDataPath = undefined;76 wda.device = {};77 wda.device.udid = 'udid';78 mocks.wda.expects('setupProxies').once().returns();79 mocks.fs.expects('exists').returns(true);80 mocks.dependencies.expects('checkForDependencies').once().returns(false);81 mocks.xcodebuild.expects('init').once().returns();82 mocks.xcodebuild.expects('start').once().returns();83 await wda.launch();84 });85 it('should not call checkForDependencies with usePrebuiltWDA and derivedDataPath', async function () {86 wda.useXctestrunFile = false;87 wda.usePrebuiltWDA = true;88 wda.derivedDataPath = 'path/to/data';89 wda.device = {};90 wda.device.udid = 'udid';91 mocks.wda.expects('setupProxies').once().returns();92 mocks.fs.expects('exists').returns(true);93 mocks.dependencies.expects('checkForDependencies').never();94 mocks.xcodebuild.expects('init').once().returns();95 mocks.xcodebuild.expects('start').once().returns();96 await wda.launch();97 });98 it('should not call checkForDependencies with useXctestrunFile', async function () {99 wda.useXctestrunFile = true;100 wda.usePrebuiltWDA = false;101 wda.derivedDataPath = undefined;102 wda.device = {};103 wda.device.udid = 'udid';104 mocks.wda.expects('setupProxies').once().returns();105 mocks.fs.expects('exists').returns(true);106 mocks.dependencies.expects('checkForDependencies').never();107 mocks.xcodebuild.expects('init').once().returns();108 mocks.xcodebuild.expects('start').once().returns();109 await wda.launch();110 });111 }));112});113describe('launch', function () {114 it('should use webDriverAgentUrl override and return current status', async function () {115 let override = 'http://mockurl:8100/';116 let args = Object.assign({}, fakeConstructorArgs);117 args.webDriverAgentUrl = override;118 let agent = new WebDriverAgent({}, args);119 let wdaStub = sinon.stub(agent, 'getStatus');120 wdaStub.callsFake(function () {121 return {build: 'data'};122 });123 await agent.launch('sessionId').should.eventually.eql({build: 'data'});124 agent.url.href.should.eql(override);125 wdaStub.reset();126 });127});128describe('get url', function () {129 it('should use default WDA listening url', function () {130 const args = Object.assign({}, fakeConstructorArgs);131 const agent = new WebDriverAgent({}, args);132 agent.url.href.should.eql('http://localhost:8100/');133 });134 it('should use default WDA listening url with emply base url', function () {135 const wdaLocalPort = '9100';136 const wdaBaseUrl = '';137 const args = Object.assign({}, fakeConstructorArgs);138 args.wdaBaseUrl = wdaBaseUrl;139 args.wdaLocalPort = wdaLocalPort;140 const agent = new WebDriverAgent({}, args);141 agent.url.href.should.eql('http://localhost:9100/');142 });143 it('should use customised WDA listening url', function () {144 const wdaLocalPort = '9100';145 const wdaBaseUrl = 'http://mockurl';146 const args = Object.assign({}, fakeConstructorArgs);147 args.wdaBaseUrl = wdaBaseUrl;148 args.wdaLocalPort = wdaLocalPort;149 const agent = new WebDriverAgent({}, args);150 agent.url.href.should.eql('http://mockurl:9100/');151 });152 it('should use customised WDA listening url with slash', function () {153 const wdaLocalPort = '9100';154 const wdaBaseUrl = 'http://mockurl/';155 const args = Object.assign({}, fakeConstructorArgs);156 args.wdaBaseUrl = wdaBaseUrl;157 args.wdaLocalPort = wdaLocalPort;158 const agent = new WebDriverAgent({}, args);159 agent.url.href.should.eql('http://mockurl:9100/');160 });161});162describe('setupCaching()', function () {163 let wda;164 let wdaStub;165 let wdaStubUninstall;166 const getTimestampStub = sinon.stub(utils, 'getWDAUpgradeTimestamp');167 beforeEach(function () {168 wda = new WebDriverAgent('1');169 wdaStub = sinon.stub(wda, 'getStatus');170 wdaStubUninstall = sinon.stub(wda, 'uninstall');171 });172 afterEach(function () {173 for (const stub of [wdaStub, wdaStubUninstall, getTimestampStub]) {174 if (stub) {175 stub.reset();176 }177 }178 });179 it('should not call uninstall since no Running WDA', async function () {180 wdaStub.callsFake(function () {181 return null;182 });183 wdaStubUninstall.callsFake(_.noop);184 await wda.setupCaching();185 wdaStub.calledOnce.should.be.true;186 wdaStubUninstall.notCalled.should.be.true;187 _.isUndefined(wda.webDriverAgentUrl).should.be.true;188 });189 it('should not call uninstall since running WDA has only time', async function () {190 wdaStub.callsFake(function () {191 return {build: { time: 'Jun 24 2018 17:08:21' }};192 });193 wdaStubUninstall.callsFake(_.noop);194 await wda.setupCaching();195 wdaStub.calledOnce.should.be.true;196 wdaStubUninstall.notCalled.should.be.true;197 wda.webDriverAgentUrl.should.equal('http://localhost:8100/');198 });199 it('should call uninstall once since bundle id is not default without updatedWDABundleId capability', async function () {200 wdaStub.callsFake(function () {201 return {build: { time: 'Jun 24 2018 17:08:21', productBundleIdentifier: 'com.example.WebDriverAgent' }};202 });203 wdaStubUninstall.callsFake(_.noop);204 await wda.setupCaching();205 wdaStub.calledOnce.should.be.true;206 wdaStubUninstall.calledOnce.should.be.true;207 _.isUndefined(wda.webDriverAgentUrl).should.be.true;208 });209 it('should call uninstall once since bundle id is different with updatedWDABundleId capability', async function () {210 wdaStub.callsFake(function () {211 return {build: { time: 'Jun 24 2018 17:08:21', productBundleIdentifier: 'com.example.different.WebDriverAgent' }};212 });213 wdaStubUninstall.callsFake(_.noop);214 await wda.setupCaching();215 wdaStub.calledOnce.should.be.true;216 wdaStubUninstall.calledOnce.should.be.true;217 _.isUndefined(wda.webDriverAgentUrl).should.be.true;218 });219 it('should not call uninstall since bundle id is equal to updatedWDABundleId capability', async function () {220 wda = new WebDriverAgent('1', { updatedWDABundleId: 'com.example.WebDriverAgent' });221 wdaStub = sinon.stub(wda, 'getStatus');222 wdaStubUninstall = sinon.stub(wda, 'uninstall');223 wdaStub.callsFake(function () {224 return {build: { time: 'Jun 24 2018 17:08:21', productBundleIdentifier: 'com.example.WebDriverAgent' }};225 });226 wdaStubUninstall.callsFake(_.noop);227 await wda.setupCaching();228 wdaStub.calledOnce.should.be.true;229 wdaStubUninstall.notCalled.should.be.true;230 wda.webDriverAgentUrl.should.equal('http://localhost:8100/');231 });232 it('should call uninstall if current revision differs from the bundled one', async function () {233 wdaStub.callsFake(function () {234 return {build: { upgradedAt: '1' }};235 });236 getTimestampStub.callsFake(() => '2');237 wdaStubUninstall.callsFake(_.noop);238 await wda.setupCaching();239 wdaStub.calledOnce.should.be.true;240 wdaStubUninstall.calledOnce.should.be.true;241 });242 it('should not call uninstall if current revision is the same as the bundled one', async function () {243 wdaStub.callsFake(function () {244 return {build: { upgradedAt: '1' }};245 });246 getTimestampStub.callsFake(() => '1');247 wdaStubUninstall.callsFake(_.noop);248 await wda.setupCaching();249 wdaStub.calledOnce.should.be.true;250 wdaStubUninstall.notCalled.should.be.true;251 });252 it('should not call uninstall if current revision cannot be retrieved from WDA status', async function () {253 wdaStub.callsFake(function () {254 return {build: {}};255 });256 getTimestampStub.callsFake(() => '1');257 wdaStubUninstall.callsFake(_.noop);258 await wda.setupCaching();259 wdaStub.calledOnce.should.be.true;260 wdaStubUninstall.notCalled.should.be.true;261 });262 it('should not call uninstall if current revision cannot be retrieved from the file system', async function () {263 wdaStub.callsFake(function () {264 return {build: { upgradedAt: '1' }};265 });266 getTimestampStub.callsFake(() => null);267 wdaStubUninstall.callsFake(_.noop);268 await wda.setupCaching();269 wdaStub.calledOnce.should.be.true;270 wdaStubUninstall.notCalled.should.be.true;271 });272 describe('uninstall', function () {273 let device;274 let wda;275 let deviceGetBundleIdsStub;276 let deviceRemoveAppStub;277 beforeEach(function () {278 device = {279 getUserInstalledBundleIdsByBundleName: () => {},280 removeApp: () => {}281 };282 wda = new WebDriverAgent('1', {device});283 deviceGetBundleIdsStub = sinon.stub(device, 'getUserInstalledBundleIdsByBundleName');284 deviceRemoveAppStub = sinon.stub(device, 'removeApp');285 });286 afterEach(function () {287 for (const stub of [deviceGetBundleIdsStub, deviceRemoveAppStub]) {288 if (stub) {289 stub.reset();290 }291 }292 });293 it('should not call uninstall', async function () {294 deviceGetBundleIdsStub.callsFake(() => []);295 await wda.uninstall();296 deviceGetBundleIdsStub.calledOnce.should.be.true;297 deviceRemoveAppStub.notCalled.should.be.true;298 });299 it('should call uninstall once', async function () {300 const uninstalledBundIds = [];301 deviceGetBundleIdsStub.callsFake(() => ['com.appium.WDA1']);302 deviceRemoveAppStub.callsFake((id) => uninstalledBundIds.push(id));303 await wda.uninstall();304 deviceGetBundleIdsStub.calledOnce.should.be.true;305 deviceRemoveAppStub.calledOnce.should.be.true;306 uninstalledBundIds.should.eql(['com.appium.WDA1']);307 });308 it('should call uninstall twice', async function () {309 const uninstalledBundIds = [];310 deviceGetBundleIdsStub.callsFake(() => ['com.appium.WDA1', 'com.appium.WDA2']);311 deviceRemoveAppStub.callsFake((id) => uninstalledBundIds.push(id));312 await wda.uninstall();313 deviceGetBundleIdsStub.calledOnce.should.be.true;314 deviceRemoveAppStub.calledTwice.should.be.true;315 uninstalledBundIds.should.eql(['com.appium.WDA1', 'com.appium.WDA2']);316 });317 });...

Full Screen

Full Screen

webdriveragent.js

Source:webdriveragent.js Github

copy

Full Screen

...96 }97 async uninstall () {98 log.debug(`Removing WDA application from device`);99 try {100 await this.device.removeApp(WDA_BUNDLE_ID);101 } catch (e) {102 log.warn(`WebDriverAgent uninstall failed. Perhaps, it is already uninstalled? Original error: ${JSON.stringify(e)}`);103 }104 }105 async launch (sessionId) {106 if (this.webDriverAgentUrl) {107 log.info(`Using provided WebdriverAgent at '${this.webDriverAgentUrl}'`);108 this.url = this.webDriverAgentUrl;109 this.setupProxies(sessionId);110 return;111 }112 log.info('Launching WebDriverAgent on the device');113 this.setupProxies(sessionId);114 if (!this.useXctestrunFile && !await fs.exists(this.agentPath)) {...

Full Screen

Full Screen

simulator-management.js

Source:simulator-management.js Github

copy

Full Screen

...129 log.debug(`App '${bundleId}' is already installed. No need to reinstall.`);130 return;131 }132 log.debug(`Reset requested. Removing app with id '${bundleId}' from the device`);133 await device.removeApp(bundleId);134 }135 }136 log.debug(`Installing ${app} on Simulator with UUID '${device.udid}'...`);137 await device.installApp(app);138 log.debug('The app has been installed successfully.');139}140export { simBooted, createSim, getExistingSim, runSimulatorReset,...

Full Screen

Full Screen

app-management.js

Source:app-management.js Github

copy

Full Screen

...40 const {bundleId} = extractMandatoryOptions(opts, ['bundleId']);41 log.info(`Uninstalling the application with bundle identifier '${bundleId}' ` +42 `from the ${this.isRealDevice() ? 'real device' : 'Simulator'} with UDID ${this.opts.device.udid}`);43 try {44 await this.opts.device.removeApp(bundleId);45 log.info(`Removal of '${bundleId}' succeeded`);46 return true;47 } catch (err) {48 log.warn(`Cannot remove '${bundleId}'. Original error: ${err.message}`);49 return false;50 }51};52commands.mobileLaunchApp = async function (opts = {}) {53 const wdaOpts = extractMandatoryOptions(opts, ['bundleId']);54 if (opts.arguments) {55 wdaOpts.arguments = _.isArray(opts.arguments) ? opts.arguments : [opts.arguments];56 }57 if (opts.environment) {58 wdaOpts.environment = opts.environment;...

Full Screen

Full Screen

general.js

Source:general.js Github

copy

Full Screen

...72commands.removeApp = async function (bundleId) {73 if (this.isRealDevice()) {74 await this.opts.device.remove(bundleId);75 } else {76 await this.opts.device.removeApp(bundleId);77 }78};79commands.launchApp = iosCommands.general.launchApp;80commands.closeApp = iosCommands.general.closeApp;81export { commands };...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const { remote } = require('webdriverio');2(async () => {3 const browser = await remote({4 capabilities: {5 }6 });7 await browser.pause(5000);8 await browser.removeApp('com.apple.Preferences');9 await browser.pause(5000);10 await browser.deleteSession();11})();12[debug] [WD Proxy] Got response with status 200: {"value":{},"sessionId":"B9E9A7D9-8B8C-4D6A-9C7C-6B8A6D0C1D4A"}13[debug] [W3C (b4e0d3c3)] Responding to client with driver.removeApp() result: {}14[HTTP] {"script":"mobile: launchApp","args":[]}15[W3C (b4e0d3c3)] Calling AppiumDriver.execute() with args: ["mobile: launchApp",[],"b4e0d3c3-3a3e-4b1e-a2f9-9a0b1d8c0f7a"]

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.execute('mobile: removeApp', {bundleId: 'com.apple.mobilesafari'}).then(function(){7 console.log('Successfully removed app');8}, function(err){9 console.log('Error occurred while removing app: ' + err);10});11driver.quit();

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriverio = require('webdriverio');2var options = {3 desiredCapabilities: {4 }5};6 .remote(options)7 .init()8 .then(function() {9 return client.removeApp('com.apple.mobilesafari');10 })11 .end();12var webdriverio = require('webdriverio');13var options = {14 desiredCapabilities: {15 }16};17 .remote(options)18 .init()19 .then(function() {20 return client.launchApp();21 })22 .end();23var webdriverio = require('webdriverio');24var options = {25 desiredCapabilities: {26 }27};28 .remote(options)29 .init()30 .then(function() {31 return client.installApp('/Users/username/Desktop/Calculator.app');32 })33 .end();34var webdriverio = require('webdriverio');35var options = {36 desiredCapabilities: {37 }38};39 .remote(options)40 .init()41 .then(function() {42 return client.isAppInstalled('com.apple.mobilesafari');43 })44 .then(function(isInstalled) {45 console.log('isInstalled', isInstalled);46 })

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2driver.init({3}).then(() => {4 return driver.removeApp('com.apple.Preferences');5}).then(() => {6 return driver.quit();7}).catch((err) => {8 console.log(err);9});

Full Screen

Using AI Code Generation

copy

Full Screen

1async function removeApp(device) {2 await device.removeApp('com.apple.Preferences');3}4async function installApp(device) {5 await device.installApp('/Users/username/Downloads/Settings.app');6}7async function launchApp(device) {8 await device.launchApp();9}10async function terminateApp(device) {11 await device.terminateApp('com.apple.Preferences');12}13async function activateApp(device) {14 await device.activateApp('com.apple.Preferences');15}16async function backgroundApp(device) {17 await device.backgroundApp(3);18}19async function reset(device) {20 await device.reset();21}22async function isAppInstalled(device) {23 await device.isAppInstalled('com.apple.Preferences');24}25async function installApp(device) {26 await device.installApp('/Users/username/Downloads/Settings.app');27}28async function removeApp(device) {29 await device.removeApp('com.apple.Preferences');30}31async function launchApp(device) {32 await device.launchApp();33}34async function terminateApp(device) {35 await device.terminateApp('com.apple.Preferences');36}

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var desired = {4};5var driver = wd.promiseChainRemote('localhost', 4723);6 .init(desired)7 .then(function() {8 return driver.removeApp('com.example.apple-samplecode.UICatalog');9 })10 .then(function() {11 return driver.quit();12 })13 .done();14I am trying to use the removeApp() method of the Appium XCUITest Driver to uninstall an app from the simulator. However, I am getting the following error:15[debug] [MJSONWP] Calling AppiumDriver.removeApp() with args: ["com.example.apple-samplecode.UICatalog","5c5b5f5b-7c58-4d8a-aa6b-1f0b5e2e8d4b"]16 at ChildProcess.proc.on.code (/usr/local/lib/node_modules/appium/node_modules/teen_process/lib/exec.js:94:19)17 at emitTwo (events.js:106:13)18 at ChildProcess.emit (events.js:191:7)19 at maybeClose (internal/child_process.js:877:16)20 at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)21[debug] [XCUITest] at XCUITestDriver.removeApp$ (lib/driver.js:1074:15)22 at tryCatch (/usr/local/lib

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const assert = require('assert');3const path = require('path');4const fs = require('fs');5const os = require('os');6const { exec } = require('child_process');7const { sleep } = require('./utils');8const BUNDLE_ID = 'com.apple.Preferences';9const APP_NAME = 'Preferences';10const driver = wd.promiseChainRemote('localhost', 4723);11const desired = {12};13(async () => {14 try {15 await driver.init(desired);16 await driver.removeApp(BUNDLE_ID);17 await driver.launchApp();18 await driver.closeApp();19 await driver.removeApp(BUNDLE_ID);20 await driver.launchApp();21 await driver.closeApp();22 await driver.removeApp(BUNDLE_ID);23 await driver.launchApp();24 await driver.closeApp();25 await driver.removeApp(BUNDLE_ID);26 await driver.launchApp();27 await driver.closeApp();28 await driver.removeApp(BUNDLE_ID);29 await driver.launchApp();30 await driver.closeApp();31 await driver.removeApp(BUNDLE_ID);32 await driver.launchApp();33 await driver.closeApp();34 await driver.removeApp(BUNDLE_ID);35 await driver.launchApp();36 await driver.closeApp();37 await driver.removeApp(BUNDLE_ID);38 await driver.launchApp();39 await driver.closeApp();40 await driver.removeApp(BUNDLE_ID);41 await driver.launchApp();42 await driver.closeApp();43 await driver.removeApp(BUNDLE_ID);44 await driver.launchApp();45 await driver.closeApp();46 await driver.removeApp(BUNDLE_ID);47 await driver.launchApp();48 await driver.closeApp();49 await driver.removeApp(BUNDLE_ID);50 await driver.launchApp();51 await driver.closeApp();52 await driver.removeApp(BUNDLE_ID);53 await driver.launchApp();54 await driver.closeApp();55 await driver.removeApp(BUNDLE_ID);56 await driver.launchApp();

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