How to use getUserInstalledBundleIdsByBundleName method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

simulator-e2e-specs.js

Source:simulator-e2e-specs.js Github

copy

Full Screen

...104 let dirs = await sim.getAppDirs('TestApp', BUNDLE_ID);105 dirs.should.have.length(2);106 dirs[0].should.contain('/Data/');107 dirs[1].should.contain('/Bundle/');108 await sim.getUserInstalledBundleIdsByBundleName('TestApp').should.eventually.not.empty;109 });110 it('should be able to delete an app', async function () {111 let sim = await getSimulator(simctl.udid);112 await sim.run({startupTimeout: LONG_TIMEOUT});113 // install & launch test app114 await installApp(sim, app);115 console.log('Application installed'); // eslint-disable-line no-console116 (await sim.isAppInstalled(BUNDLE_ID)).should.be.true;117 // this remains somewhat flakey118 await retryInterval(5, 1000, async () => {119 await simctl.launchApp(BUNDLE_ID, 1);120 });121 console.log('Application launched'); // eslint-disable-line no-console122 // Wait for application process123 await waitForCondition(124 async () => (await sim.ps()).some(({name}) => name === BUNDLE_ID), {125 waitMs: 10000,126 intervalMs: 500,127 });128 await sim.removeApp(BUNDLE_ID);129 // should not be able to launch anymore130 await simctl.launchApp(BUNDLE_ID, 1).should.eventually.be.rejected;131 (await sim.isAppInstalled(BUNDLE_ID)).should.be.false;132 });133 it('should delete custom app data', async function () {134 let sim = await getSimulator(simctl.udid);135 await sim.run({startupTimeout: LONG_TIMEOUT});136 // install & launch test app137 await installApp(sim, app);138 // this remains somewhat flakey139 await retryInterval(5, 1000, async () => {140 await simctl.launchApp(BUNDLE_ID, 1);141 });142 // delete app directories143 await sim.cleanCustomApp('TestApp', BUNDLE_ID);144 // clear paths to force the simulator to get a new list of directories145 sim.appDataBundlePaths = {};146 let dirs = await sim.getAppDirs('TestApp', BUNDLE_ID);147 dirs.should.have.length(0);148 });149 it('should delete a sim', async function () {150 let sim = await getSimulator(simctl.udid);151 await sim.delete();152 await getSimulator(simctl.udid).should.eventually.be.rejected;153 });154 let itText = 'should match a bundleId to its app directory on a used sim';155 let bundleId = 'com.apple.mobilesafari';156 if (OS_VERSION === '7.1') {157 itText = 'should match an app to its app directory on a used sim';158 bundleId = 'MobileSafari';159 }160 it(itText, async function () {161 let sim = await getSimulator(simctl.udid);162 await sim.launchAndQuit(false, LONG_TIMEOUT);163 let path = await sim.getAppDir(bundleId);164 await fs.hasAccess(path).should.eventually.be.true;165 });166 itText = 'should not match a bundleId to its app directory on a fresh sim';167 bundleId = 'com.apple.mobilesafari';168 if (OS_VERSION === '7.1') {169 itText = 'should not match an app to its app directory on a fresh sim';170 bundleId = 'MobileSafari';171 }172 it(itText, async function () {173 let sim = await getSimulator(simctl.udid);174 let path = await sim.getAppDir(bundleId);175 chai.should().equal(path, undefined);176 });177 it('should start a sim using the "run" method', async function () {178 let sim = await getSimulator(simctl.udid);179 await sim.run({startupTimeout: LONG_TIMEOUT});180 let stat = await sim.stat();181 stat.state.should.equal('Booted');182 await sim.shutdown();183 stat = await sim.stat();184 stat.state.should.equal('Shutdown');185 });186 it('should be able to start safari', async function () {187 let sim = await getSimulator(simctl.udid);188 await sim.run({startupTimeout: LONG_TIMEOUT});189 await sim.openUrl('http://apple.com');190 await sim.shutdown();191 // this test to catch errors in openUrl, that arise from bad sims or certain versions of xcode192 });193 it('should detect if a sim is running', async function () {194 let sim = await getSimulator(simctl.udid);195 let running = await sim.isRunning();196 running.should.be.false;197 await sim.run({startupTimeout: LONG_TIMEOUT});198 running = await sim.isRunning();199 running.should.be.true;200 await sim.shutdown();201 running = await sim.isRunning();202 running.should.be.false;203 });204 it('should isolate sim', async function () {205 let sim = await getSimulator(simctl.udid);206 await sim.isolateSim();207 });208 it('should apply calendar access to simulator', async function () {209 let sim = await getSimulator(simctl.udid);210 if ((xcodeVersion.major === 11 && xcodeVersion.minor >= 4) || xcodeVersion.major >= 12) {211 await sim.run({startupTimeout: LONG_TIMEOUT});212 await sim.enableCalendarAccess(BUNDLE_ID);213 await sim.disableCalendarAccess(BUNDLE_ID);214 } else {215 await sim.enableCalendarAccess(BUNDLE_ID);216 (await sim.hasCalendarAccess(BUNDLE_ID)).should.be.true;217 await sim.disableCalendarAccess(BUNDLE_ID);218 (await sim.hasCalendarAccess(BUNDLE_ID)).should.be.false;219 }220 });221 it('should properly start simulator in headless mode on Xcode9+', async function () {222 if (xcodeVersion.major < 9) {223 return this.skip();224 }225 const sim = await getSimulator(simctl.udid);226 await verifyStates(sim, false, false);227 await sim.run({228 startupTimeout: LONG_TIMEOUT,229 isHeadless: false,230 });231 await verifyStates(sim, true, true);232 await sim.run({233 startupTimeout: LONG_TIMEOUT,234 isHeadless: true,235 });236 await verifyStates(sim, true, false);237 await sim.shutdown();238 await verifyStates(sim, false, false);239 });240});241describe(`reuse an already-created already-run simulator ${OS_VERSION}`, function () {242 this.timeout(LONG_TIMEOUT);243 this.retries(2);244 let sim;245 before(async function () {246 await killAllSimulators();247 const udid = await new Simctl().createDevice(248 'ios-simulator testing',249 DEVICE_NAME,250 OS_VERSION);251 sim = await getSimulator(udid);252 await sim.run({startupTimeout: LONG_TIMEOUT});253 await sim.shutdown();254 await B.delay(4000);255 });256 after(async function () {257 await killAllSimulators();258 await deleteSimulator(sim.udid, OS_VERSION);259 });260 it('should start a sim using the "run" method', async function () {261 await sim.run({startupTimeout: LONG_TIMEOUT});262 let stat = await sim.stat();263 stat.state.should.equal('Booted');264 await sim.shutdown();265 stat = await sim.stat();266 stat.state.should.equal('Shutdown');267 });268});269describe('advanced features', function () {270 let sim;271 this.timeout(LONG_TIMEOUT);272 before(async function () {273 await killAllSimulators();274 const udid = await new Simctl().createDevice(275 'ios-simulator testing',276 DEVICE_NAME,277 OS_VERSION);278 sim = await getSimulator(udid);279 await sim.run({280 startupTimeout: LONG_TIMEOUT,281 });282 });283 after(async function () {284 await killAllSimulators();285 await deleteSimulator(sim.udid, OS_VERSION);286 });287 describe('biometric (touch Id/face Id enrollment)', function () {288 it(`should properly enroll biometric to enabled state`, async function () {289 if (process.env.DEVICE && parseFloat(process.env.DEVICE) < 11) {290 return this.skip();291 }292 await sim.enrollBiometric(true);293 (await sim.isBiometricEnrolled()).should.be.true;294 });295 it(`should properly enroll biometric to disabled state`, async function () {296 if (process.env.DEVICE && parseFloat(process.env.DEVICE) < 11) {297 return this.skip();298 }299 await sim.enrollBiometric(false);300 (await sim.isBiometricEnrolled()).should.be.false;301 });302 });303 describe('configureLocalization', function () {304 it(`should properly set locale settings`, async function () {305 if (!_.isFunction(sim.configureLocalization)) {306 return this.skip();307 }308 await sim.configureLocalization({309 language: {310 name: 'en'311 },312 locale: {313 name: 'en_US',314 calendar: 'gregorian',315 },316 keyboard: {317 name: 'en_US',318 layout: 'QWERTY',319 }320 });321 });322 });323 describe('keychains', function () {324 this.retries(2);325 it('should properly backup and restore Simulator keychains', async function () {326 if (await sim.backupKeychains()) {327 (await sim.restoreKeychains('*.db*')).should.be.true;328 }329 });330 it('should clear Simulator keychains while it is running', async function () {331 await sim.clearKeychains().should.eventually.be.fulfilled;332 });333 });334 describe(`setReduceMotion`, function () {335 it('should check accessibility reduce motion settings', async function () {336 await sim.setReduceMotion(true);337 let fileSettings = await readSettings(sim, 'accessibilitySettings');338 for (const [, settings] of _.toPairs(fileSettings)) {339 settings.ReduceMotionEnabled.should.eql(1);340 }341 await sim.setReduceMotion(false);342 fileSettings = await readSettings(sim, 'accessibilitySettings');343 for (const [, settings] of _.toPairs(fileSettings)) {344 settings.ReduceMotionEnabled.should.eql(0);345 }346 });347 });348 describe('updateSafariGlobalSettings', function () {349 it('should set an arbitrary preference on the global Safari plist', async function () {350 await sim.updateSafariGlobalSettings({351 DidImportBuiltinBookmarks: true,352 });353 let setSettings = await readSettings(sim, 'globalMobileSafari');354 for (const [file, settings] of _.toPairs(setSettings)) {355 file.endsWith('data/Library/Preferences/com.apple.mobilesafari.plist').should.be.true;356 settings.DidImportBuiltinBookmarks.should.eql(true);357 }358 await sim.updateSafariGlobalSettings({359 DidImportBuiltinBookmarks: false,360 });361 setSettings = await readSettings(sim, 'globalMobileSafari');362 for (const [file, settings] of _.toPairs(setSettings)) {363 file.endsWith('data/Library/Preferences/com.apple.mobilesafari.plist').should.be.true;364 settings.DidImportBuiltinBookmarks.should.eql(false);365 }366 });367 });368});369describe(`multiple instances of ${OS_VERSION} simulator on Xcode9+`, function () {370 this.timeout(LONG_TIMEOUT * 2);371 this.retries(2);372 let simulatorsMapping = {};373 const DEVICES_COUNT = 2;374 before(async function () {375 if (_.isEmpty(xcodeVersion)) {376 xcodeVersion = await xcode.getVersion(true);377 }378 if (xcodeVersion.major < 9) {379 return this.skip();380 }381 await killAllSimulators();382 const simctl = new Simctl();383 for (let i = 0; i < DEVICES_COUNT; i++) {384 const udid = await simctl.createDevice(385 `ios-simulator_${i}_testing`,386 DEVICE_NAME,387 OS_VERSION);388 simulatorsMapping[udid] = await getSimulator(udid);389 }390 });391 after(async function () {392 try {393 await killAllSimulators();394 const simctl = new Simctl();395 for (const udid of _.keys(simulatorsMapping)) {396 try {397 simctl.udid = udid;398 await simctl.deleteDevice();399 } catch (err) {400 console.log(`Error deleting simulator '${udid}': ${err.message}`); // eslint-disable-line401 }402 }403 } finally {404 simulatorsMapping = {};405 }406 });407 beforeEach(killAllSimulators);408 afterEach(killAllSimulators);409 it(`should start multiple simulators in 'default' mode`, async function () {410 const simulators = _.values(simulatorsMapping);411 // they all should be off412 await retryInterval(30, 1000, async function () {413 await B.map(simulators, (sim) => verifyStates(sim, false, false));414 });415 // Should be called before launching simulator416 await simulators[0].getUserInstalledBundleIdsByBundleName('UICatalog').should.eventually.eql([]);417 for (const sim of _.values(simulatorsMapping)) {418 await sim.run({startupTimeout: LONG_TIMEOUT});419 }420 await retryInterval(30, 1000, async function () {421 await B.map(simulators, (sim) => verifyStates(sim, true, true));422 });423 for (const sim of _.values(simulatorsMapping)) {424 await sim.shutdown();425 }426 await retryInterval(30, 1000, async function () {427 await B.map(simulators, (sim) => verifyStates(sim, false, true));428 });429 });430});...

Full Screen

Full Screen

webdriveragent.js

Source:webdriveragent.js Github

copy

Full Screen

...141 * Appium does not expect multiple WDAs are running on a device.142 */143 async uninstall () {144 try {145 const bundleIds = await this.device.getUserInstalledBundleIdsByBundleName(WDA_CF_BUNDLE_NAME);146 if (_.isEmpty(bundleIds)) {147 log.debug('No WDAs on the device.');148 return;149 }150 log.debug(`Uninstalling WDAs: '${bundleIds}'`);151 for (const bundleId of bundleIds) {152 await this.device.removeApp(bundleId);153 }154 } catch (e) {155 log.warn(`WebDriverAgent uninstall failed. Perhaps, it is already uninstalled? Original error: ${JSON.stringify(e)}`);156 }157 }158 /**159 * Return current running WDA's status like below after launching WDA...

Full Screen

Full Screen

webdriveragent-specs.js

Source:webdriveragent-specs.js Github

copy

Full Screen

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

Full Screen

Full Screen

ios-deploy.js

Source:ios-deploy.js Github

copy

Full Screen

1/* eslint-disable promise/prefer-await-to-callbacks */2import { fs } from 'appium-support';3import path from 'path';4import { services } from 'appium-ios-device';5import B from 'bluebird';6import log from './logger';7import _ from 'lodash';8const APPLICATION_INSTALLED_NOTIFICATION = 'com.apple.mobile.application_installed';9const INSTALLATION_STAGING_DIR = 'PublicStaging';10const ITEM_PUSH_TIMEOUT = 30 * 1000;11const APPLICATION_NOTIFICATION_TIMEOUT = 30 * 1000;12class IOSDeploy {13 constructor (udid) {14 this.udid = udid;15 }16 async remove (bundleid) {17 const service = await services.startInstallationProxyService(this.udid);18 try {19 await service.uninstallApplication(bundleid);20 } finally {21 service.close();22 }23 }24 async removeApp (bundleId) {25 await this.remove(bundleId);26 }27 async install (app) {28 const start = new Date();29 try {30 const bundlePathOnPhone = await this.pushAppBundle(app);31 await this.installApplication(bundlePathOnPhone);32 log.info(`Installation is successful after ${new Date() - start}ms`);33 } catch (e) {34 log.error('Error was thrown during the installation process', e);35 throw new Error(`Could not install app: '${e.message}'`);36 }37 }38 async installApplication (bundlePathOnPhone) {39 const notificationService = await services.startNotificationProxyService(this.udid);40 const installationService = await services.startInstallationProxyService(this.udid);41 const appInstalledNotification = new B((resolve) => {42 notificationService.observeNotification(APPLICATION_INSTALLED_NOTIFICATION, { notification: resolve });43 });44 try {45 await installationService.installApplication(bundlePathOnPhone, { PackageType: 'Developer'});46 try {47 await appInstalledNotification.timeout(APPLICATION_NOTIFICATION_TIMEOUT, `Couldn't get the application installed notification within ${APPLICATION_NOTIFICATION_TIMEOUT}ms but we will continue`);48 } catch (e) {49 log.warn(`Failed to receive the notification. Error: ${e.message}`);50 }51 } finally {52 installationService.close();53 notificationService.close();54 }55 }56 async pushAppBundle (app) {57 const start = new Date();58 const afcService = await services.startAfcService(this.udid);59 // We are pushing serially due to this https://github.com/appium/appium/issues/13115. There is nothing else we can do besides this60 try {61 const bundlePathOnPhone = await this.createAppPath(afcService, app);62 await fs.walkDir(app, true, async (itemPath, isDir) => {63 const pathOnPhone = path.join(bundlePathOnPhone, path.relative(app, itemPath));64 if (isDir) {65 await afcService.createDirectory(pathOnPhone);66 } else {67 const readStream = fs.createReadStream(itemPath, {autoClose: true});68 const writeStream = await afcService.createWriteStream(pathOnPhone, {autoDestroy: true });69 writeStream.on('finish', writeStream.destroy);70 const itemPushWait = new B((resolve, reject) => {71 writeStream.on('close', resolve);72 writeStream.on('error', reject);73 });74 readStream.pipe(writeStream);75 await itemPushWait.timeout(ITEM_PUSH_TIMEOUT, `Couldn't push '${itemPath}' within the timeout ${ITEM_PUSH_TIMEOUT}ms`);76 }77 });78 log.debug(`Pushed the app files successfully after ${new Date() - start}ms`);79 return bundlePathOnPhone;80 } finally {81 afcService.close();82 }83 }84 async createAppPath (afcService, localAppPath) {85 const basename = path.basename(localAppPath);86 const relativePath = path.join(INSTALLATION_STAGING_DIR, basename);87 try {88 await afcService.deleteDirectory(relativePath);89 } catch (ign) {}90 await afcService.createDirectory(relativePath);91 return relativePath;92 }93 async installApp (app) {94 await this.install(app);95 }96 /**97 * Return an application object if test app has 'bundleid'.98 * The target bundleid can be User and System apps.99 * @param {string} bundleid The bundleId to ensure it is installed100 * @return {boolean} Returns True if the bundleid exists in the result of 'listApplications' like:101 * { "com.apple.Preferences":{102 * "UIRequiredDeviceCapabilities":["arm64"],103 * "UIRequiresFullScreen":true,104 * "CFBundleInfoDictionaryVersion":"6.0",105 * "Entitlements":106 * {"com.apple.frontboard.delete-application-snapshots":true,..107 */108 async isAppInstalled (bundleid) {109 const service = await services.startInstallationProxyService(this.udid);110 try {111 const applications = await service.lookupApplications({ bundleIds: bundleid });112 return !!applications[bundleid];113 } finally {114 service.close();115 }116 }117 /**118 * @param {string} bundleName The name of CFBundleName in Info.plist119 *120 * @returns {Array<string>} A list of User level apps' bundle ids which has121 * 'CFBundleName' attribute as 'bundleName'.122 */123 async getUserInstalledBundleIdsByBundleName (bundleName) {124 const service = await services.startInstallationProxyService(this.udid);125 try {126 const applications = await service.listApplications({applicationType: 'User'});127 return _.reduce(applications, (acc, {CFBundleName}, key) => {128 if (CFBundleName === bundleName) {129 acc.push(key);130 }131 return acc;132 }, []);133 } finally {134 service.close();135 }136 }137}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const chai = require('chai');3const chaiAsPromised = require('chai-as-promised');4chai.use(chaiAsPromised);5const should = chai.should();6const assert = chai.assert;7const _ = require('lodash');8const {exec} = require('teen_process');9const path = require('path');10const fs = require('fs');11const B = require('bluebird');12const { fs: fsUtils } = require('appium-support');13const { getSimulator } = require('appium-ios-simulator');14const { getDevices } = require('node-simctl');15const SIM_DEVICE_NAME = 'iPhone 8';16const SIM_DEVICE_OS = '13.3';17const SIM_DEVICE_UDID = 'E9C9A3C3-1A3F-4A2A-8F4C-2B4B4B8E9E9C';18const TEST_APP_BUNDLE_ID = 'com.example.apple-samplecode.UICatalog';19const TEST_APP_BUNDLE_NAME = 'UICatalog';20const TEST_APP_NAME = 'UICatalog.app';21const TEST_APP_PATH = path.resolve(__dirname, '..', '..', '..', 'assets', 'UICatalog.app.zip');22const TEST_APP_DIR = path.resolve(__dirname, '..', '..', '..', 'assets', 'UICatalog.app');23const TEST_APP_UNZIPPED_PATH = path.resolve(__dirname, '..', '..', '..', 'assets', 'UICatalog.app');24const TEST_APP_BUNDLE_ID = 'com.example.apple-samplecode.UICatalog';25const TEST_APP_BUNDLE_NAME = 'UICatalog';26const TEST_APP_NAME = 'UICatalog.app';27async function installAppToSimulator (sim, appPath) {28 const bundleId = await sim.installApp(appPath);29 await sim.run(bundleId);30}31async function uninstallAppFromSimulator (sim, bundleId) {32 await sim.removeApp(bundleId);33}34async function launchApp (udid, bundleId) {35 await exec('xcrun', ['simctl', 'launch', udid, bundleId]);36}37async function killApp (udid, bundleId) {38 await exec('xcrun', ['simctl', 'terminate', udid, bundleId]);39}40async function deleteSimulator (udid) {41 await exec('xcrun', ['simctl', 'delete', udid]);42}

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const chai = require('chai');3const chaiAsPromised = require('chai-as-promised');4chai.use(chaiAsPromised);5const expect = chai.expect;6describe('WebdriverIO and Appium, when interacting with an iOS simulator', () => {7 let driver;8 before(async () => {9 await driver.init({10 });11 await driver.setImplicitWaitTimeout(5000);12 });13 after(async () => {14 await driver.quit();15 });16 it('should be able to get the list of installed apps', async () => {17 const bundleIds = await driver.getUserInstalledBundleIdsByBundleName('Safari');18 console.log(bundleIds);19 expect(bundleIds).to.have.length(1);20 });21});

Full Screen

Using AI Code Generation

copy

Full Screen

1const {remote} = require('webdriverio');2const opts = {3 capabilities: {4 }5};6(async function main() {7 const client = await remote(opts);8 const bundleIds = await client.getUserInstalledBundleIdsByBundleName('Safari');9 console.log(bundleIds);10 await client.deleteSession();11})();

Full Screen

Using AI Code Generation

copy

Full Screen

1var appium = require('appium');2var appiumXcuitestDriver = require('appium-xcuitest-driver');3var driver = new appiumXcuitestDriver();4var bundleIds = driver.getUserInstalledBundleIdsByBundleName('Calculator');5var appium = require('appium');6var appiumXCUITestDriver = require('appium-xcuitest-driver');7var driver = new appiumXCUITestDriver();8var bundleIds = driver.getUserInstalledBundleIdsByBundleName('Calculator');9var appium = require('appium');10var appiumXCUITestDriver = require('appium-xcuitest-driver');11var driver = new appiumXCUITestDriver();12var bundleIds = driver.getUserInstalledBundleIdsByBundleName('Calculator');13var appium = require('appium');14var appiumXCUITestDriver = require('appium-xcuitest-driver');15var driver = new appiumXCUITestDriver();16var bundleIds = driver.getUserInstalledBundleIdsByBundleName('Calculator');17var appium = require('appium');18var appiumXCUITestDriver = require('appium-xcuitest-driver');19var driver = new appiumXCUITestDriver();20var bundleIds = driver.getUserInstalledBundleIdsByBundleName('Calculator');21var appium = require('appium');22var appiumXCUITestDriver = require('appium-xcuitest-driver');23var driver = new appiumXCUITestDriver();24var bundleIds = driver.getUserInstalledBundleIdsByBundleName('Calculator');25var appium = require('appium');26var appiumXCUITestDriver = require('appium-xc

Full Screen

Using AI Code Generation

copy

Full Screen

1import { assert } from 'chai';2import { ios } from 'appium-base-driver';3import { getSimulator } from 'appium-ios-simulator';4import { XCUITestDriver } from 'appium-xcuitest-driver';5const xcodeVersion = await ios.getXcodeVersion();6const sim = await getSimulator(xcodeVersion.versionString);7const driver = new XCUITestDriver();8const bundleIds = await driver.getUserInstalledBundleIdsByBundleName(sim, 'Safari');9assert.equal(bundleIds.length, 1);10assert.equal(bundleIds[0], 'com.apple.mobilesafari');11import { getSimulator } from 'appium-ios-simulator';12import { ios } from 'appium-base-driver';13import { getBundleIdsFromInstalledApps } from 'appium-ios-device';14async getUserInstalledBundleIdsByBundleName (sim, bundleName) {15 const xcodeVersion = await ios.getXcodeVersion();16 const sim = await getSimulator(xcodeVersion.versionString);17 const bundleIds = await getBundleIdsFromInstalledApps(sim);18 const filteredBundleIds = bundleIds.filter((bundleId) => bundleId.includes(bundleName));19 return filteredBundleIds;20}21import { getBundleIdsFromInstalledApps } from 'appium-ios-device';22async getBundleIdsFromInstalledApps () {23 const udid = this.opts.udid;24 const bundleIds = await getBundleIdsFromInstalledApps(udid);25 return bundleIds;26}27import { getBundleIdsFromInstalledApps } from 'appium-ios-device';28async getBundleIdsFromInstalledApps () {29 const udid = this.opts.udid;30 const bundleIds = await getBundleIdsFromInstalledApps(udid);31 return bundleIds;32}33import { getBundleIdsFrom

Full Screen

Using AI Code Generation

copy

Full Screen

1var wd = require('wd');2var assert = require('assert');3var desired = {4};5driver.init(desired).then(function() {6 return driver.execute('mobile: getUserInstalledBundleIdsByBundleName', {7 });8}).then(function(bundleIds) {9 console.log(bundleIds);10 assert.ok(bundleIds.length > 0);11}).fin(function() {12 return driver.quit();13}).done();14var wd = require('wd');15var assert = require('assert');16var desired = {17};18driver.init(desired).then(function() {19 return driver.execute('mobile: launchAppWithBundleId', {20 });21}).then(function(bundleIds) {22 console.log(bundleIds);23}).fin(function() {24 return driver.quit();25}).done();26var wd = require('wd');27var assert = require('assert');28var desired = {29};30driver.init(desired).then(function() {31 return driver.execute('mobile: openURL', {32 });33}).then(function(bundleIds

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const chai = require('chai');3const chaiAsPromised = require('chai-as-promised');4const { XCUITestDriver } = require('appium-xcuitest-driver');5chai.should();6chai.use(chaiAsPromised);7async function main() {8 await driver.init({

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