How to use service.lookupApplications method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

devicelog.module.js

Source:devicelog.module.js Github

copy

Full Screen

1// Localization completed2angular.module('plugin-devicelog', ['ngResource', 'ui.bootstrap', 'ui.router', 'ngTagsInput', 'ncy-angular-breadcrumb'])3    .config(function ($stateProvider) {4        // TODO : #5937 : Localization : localize ncyBreadcrumb.label5        try {6            $stateProvider.state('plugin-devicelog', {7                url: "/" + 'plugin-devicelog',8                templateUrl: 'app/components/main/view/content.html',9                controller: 'TabController',10                ncyBreadcrumb: {11                    label: '{{"breadcrumb.plugin.devicelog.main" | localize}}', //label to show in breadcrumbs12                },13                resolve: {14                    openTab: function () {15                        return 'plugin-devicelog';16                    }17                },18            });19        } catch (e) {20            console.log('An error when adding state ' + 'plugin-devicelog', e);21        }22        try {23            $stateProvider.state('plugin-settings-devicelog', {24                url: "/" + 'plugin-settings-devicelog',25                templateUrl: 'app/components/main/view/content.html',26                controller: 'TabController',27                ncyBreadcrumb: {28                    label: '{{"breadcrumb.plugin.devicelog.main" | localize}}', //label to show in breadcrumbs29                },30                resolve: {31                    openTab: function () {32                        return 'plugin-settings-devicelog'33                    }34                },35            });36        } catch (e) {37            console.log('An error when adding state ' + 'plugin-settings-devicelog', e);38        }39    })40    .factory('pluginDeviceLogService', function ($resource) {41        return $resource('', {}, {42            getSettings: {url: 'rest/plugins/devicelog/devicelog-plugin-settings/private', method: 'GET'},43            saveSettings: {url: 'rest/plugins/devicelog/devicelog-plugin-settings/private', method: 'PUT'},44            saveSettingsRule: {url: 'rest/plugins/devicelog/devicelog-plugin-settings/private/rule', method: 'PUT'},45            deleteSettingsRule: {url: 'rest/plugins/devicelog/devicelog-plugin-settings/private/rule/:id', method: 'DELETE'},46            getLogs: {url: 'rest/plugins/devicelog/log/private/search', method: 'POST'},47            exportLogs: {48                url: 'rest/plugins/devicelog/log/private/search/export',49                method: 'POST',50                responseType: 'arraybuffer',51                cache: false,52                transformResponse: function (data) {53                    return {54                        response: new Blob([data], {55                            type: "text/plain"56                        })57                    };58                }59            },60            lookupDevices: {url: 'rest/private/devices/autocomplete', method: 'POST'},61            lookupApplications: {url: 'rest/private/applications/autocomplete', method: 'POST'},62            lookupGroups: {url: 'rest/private/groups/autocomplete', method: 'POST'},63            lookupConfigurations: {url: 'rest/private/configurations/autocomplete', method: 'POST'},64        });65    })66    .controller('PluginDeviceLogTabController', function ($scope, $rootScope, $window, $location, $interval, $http,67                                                          pluginDeviceLogService, confirmModal,68                                                          authService, localization) {69        $scope.hasPermission = authService.hasPermission;70        $rootScope.settingsTabActive = false;71        $rootScope.pluginsTabActive = true;72        $scope.paging = {73            pageNum: 1,74            pageSize: 50,75            totalItems: 0,76            deviceFilter: '',77            messageFilter: '',78            applicationFilter: null,79            severity: -1,80            dateFrom: null,81            dateTo: null,82            sortValue: 'createTime'83        };84        $scope.$watch('paging.pageNum', function() {85            $window.scrollTo(0, 0);86        });87        let deviceNumber = ($location.search()).deviceNumber;88        if (deviceNumber) {89            $scope.paging.deviceFilter = deviceNumber;90        }91        $scope.dateFormat = localization.localize('format.date.plugin.devicelog.datePicker');92        $scope.createTimeFormat = localization.localize('format.date.plugin.devicelog.createTime');93        $scope.datePickerOptions = { 'show-weeks': false };94        $scope.openDatePickers = {95            'dateFrom': false,96            'dateTo': false97        };98        $scope.errorMessage = undefined;99        $scope.successMessage = undefined;100        var getDeviceInfo = function( device ) {101            if ( device.info ) {102                try {103                    return JSON.parse( device.info );104                } catch ( e ) {}105            }106            return undefined;107        };108        var resolveDeviceField = function (serverData, deviceInfoData) {109            if (serverData === deviceInfoData) {110                return serverData;111            } else if (serverData.length === 0 && deviceInfoData.length > 0) {112                return deviceInfoData;113            } else if (serverData.length > 0 && deviceInfoData.length === 0) {114                return serverData;115            } else {116                return deviceInfoData;117            }118        };119        $scope.getDevices = function(val) {120            return pluginDeviceLogService.lookupDevices(val).$promise.then(function(response){121                if (response.status === 'OK') {122                    return response.data.map(function (device) {123                        var deviceInfo = getDeviceInfo(device);124                        var serverIMEI = device.imei || '';125                        var deviceInfoIMEI = deviceInfo ? (deviceInfo.imei || '') : '';126                        var resolvedIMEI = resolveDeviceField(serverIMEI, deviceInfoIMEI);127                        return device.name + (resolvedIMEI.length > 0 ? " / " + resolvedIMEI : "");128                    });129                } else {130                    return [];131                }132            });133        };134        $scope.deviceLookupFormatter = function (v) {135            if (v) {136                var pos = v.indexOf('/');137                if (pos > -1) {138                    return v.substr(0, pos);139                }140            }141            return v;142        };143        $scope.getApplications = function(val) {144            return pluginDeviceLogService.lookupApplications(val).$promise.then(function(response){145                if (response.status === 'OK') {146                    return response.data.map(function (app) {147                        return app.name;148                    });149                } else {150                    return [];151                }152            });153        };154        $scope.openDateCalendar = function( $event, isStartDate ) {155            $event.preventDefault();156            $event.stopPropagation();157            if ( isStartDate ) {158                $scope.openDatePickers.dateFrom = true;159            } else {160                $scope.openDatePickers.dateTo = true;161            }162        };163        $scope.search = function () {164            $scope.errorMessage = undefined;165            if ($scope.paging.dateFrom && $scope.paging.dateTo) {166                if ($scope.paging.dateFrom > $scope.paging.dateTo) {167                    $scope.errorMessage = localization.localize('error.plugin.devicelog.date.range.invalid');168                    return;169                }170            }171            $scope.paging.pageNum = 1;172            loadData();173        };174        $scope.exportFile = function () {175            $scope.errorMessage = undefined;176            if ($scope.paging.dateFrom && $scope.paging.dateTo) {177                if ($scope.paging.dateFrom > $scope.paging.dateTo) {178                    $scope.errorMessage = localization.localize('error.plugin.devicelog.date.range.invalid');179                    return;180                }181            }182            var request = {};183            for (var p in $scope.paging) {184                if ($scope.paging.hasOwnProperty(p)) {185                    request[p] = $scope.paging[p];186                }187            }188            request.deviceFilter = $scope.deviceLookupFormatter(request.deviceFilter);189            pluginDeviceLogService.exportLogs(request, function (data) {190                var downloadableBlob = URL.createObjectURL(data.response);191                var link = document.createElement('a');192                link.href = downloadableBlob;193                link.download = 'logs.txt';194                document.body.appendChild(link);195                link.click();196                document.body.removeChild(link);197            }, function () {198                $scope.errorMessage = localization.localize('error.request.failure');199            });200        };201        $scope.$watch('paging.pageNum', function () {202            loadData();203        });204        var loading = false;205        var loadData = function () {206            $scope.errorMessage = undefined;207            208            if (loading) {209                console.log("Skipping to query for list of log record since a previous request is pending");210                return;211            }212            loading = true;213            var request = {};214            for (var p in $scope.paging) {215                if ($scope.paging.hasOwnProperty(p)) {216                    request[p] = $scope.paging[p];217                }218            }219            request.deviceFilter = $scope.deviceLookupFormatter(request.deviceFilter);220            pluginDeviceLogService.getLogs(request, function (response) {221                loading = false;222                if (response.status === 'OK') {223                    $scope.logs = response.data.items;224                    $scope.paging.totalItems = response.data.totalItemsCount;225                } else {226                    $scope.errorMessage = localization.localizeServerResponse(response);227                }228            }, function () {229                loading = false;230                $scope.errorMessage = localization.localize('error.request.failure');231            })232        };233        loadData();234        var reloadData = function() {235            if ($scope.paging.pageNum == 1) {236                loadData();237            }238        }239        var autoUpdateInterval = $interval(reloadData, 15000);240        $scope.$on('$destroy', function () {241            if (autoUpdateInterval) $interval.cancel(autoUpdateInterval);242        });243    })244    .controller('PluginDeviceLogSettingsController', function ($scope, $rootScope, $modal,245                                                               confirmModal, localization, pluginDeviceLogService) {246        $scope.successMessage = undefined;247        $scope.errorMessage = undefined;248        $rootScope.settingsTabActive = true;249        $rootScope.pluginsTabActive = false;250        $scope.settings = {};251        pluginDeviceLogService.getSettings(function (response) {252            if (response.status === 'OK') {253                $scope.settings = response.data;254                if (!$scope.settings.rules) {255                    $scope.settings.rules = [];256                }257            } else {258                $scope.errorMessage = localization.localize(response.message);259            }260        });261        $scope.save = function () {262            $scope.successMessage = undefined;263            $scope.errorMessage = undefined;264            var copy = {};265            for (var p in $scope.settings) {266                if ($scope.settings.hasOwnProperty(p)) {267                    copy[p] = $scope.settings[p];268                }269            }270            delete copy.rules;271            pluginDeviceLogService.saveSettings(copy, function (response) {272                if (response.status === 'OK') {273                    $scope.successMessage = localization.localize('success.plugin.devicelog.settings.saved');274                } else {275                    $scope.errorMessage = localization.localizeServerResponse(response);276                }277            });278        };279        $scope.removeRule = function (rule) {280            let localizedText = localization.localize('plugin.devicelog.settings.question.delete.rule').replace('${rulename}', rule.name);281            confirmModal.getUserConfirmation(localizedText, function () {282                pluginDeviceLogService.deleteSettingsRule({id: rule.id}, function (response) {283                    if (response.status === 'OK') {284                        refreshRules();285                    } else {286                        alertService.showAlertMessage(localization.localize('error.internal.server'));287                    }288                });289            });290        };291        $scope.editRule = function (rule) {292            var modalInstance = $modal.open({293                templateUrl: 'app/components/plugins/devicelog/views/rule.modal.html',294                controller: 'PluginDeviceLogEditRuleController',295                resolve: {296                    rule: function () {297                        return rule;298                    }299                }300            });301            modalInstance.result.then(function (saved) {302                if (saved) {303                    refreshRules();304                }305            });306        };307        var refreshRules = function () {308            pluginDeviceLogService.getSettings(function (response) {309                if (response.status === 'OK') {310                    $scope.settings.rules = response.data.rules;311                } else {312                    $scope.errorMessage = localization.localize(response.message);313                }314            });315        };316    })317    .controller('PluginDeviceLogEditRuleController', function ($scope, $modal, $modalInstance, $http,318                                                               localization, pluginDeviceLogService, rule) {319        var ruleCopy = {};320        for (var p in rule) {321            if (rule.hasOwnProperty(p)) {322                ruleCopy[p] = rule[p];323            }324        }325        $scope.rule = ruleCopy;326        $scope.saving = false;327        var appCandidates = [];328        var groupCandidates = [];329        var configurationCandidates = [];330        $scope.getApplications = function(val) {331            return pluginDeviceLogService.lookupApplications(val).$promise.then(function(response){332                if (response.status === 'OK') {333                    appCandidates = response.data;334                    return response.data.map(function (item) {335                        return item.name;336                    });337                } else {338                    appCandidates = [];339                    return [];340                }341            });342        };343        $scope.getGroups = function(val) {344            return pluginDeviceLogService.lookupGroups(val).$promise.then(function(response){345                if (response.status === 'OK') {346                    groupCandidates = response.data;347                    return response.data.map(function (item) {348                        return item.name;349                    });350                } else {351                    groupCandidates = [];352                    return [];353                }354            });355        };356        $scope.getConfigurations = function(val) {357            return pluginDeviceLogService.lookupConfigurations(val).$promise.then(function(response){358                if (response.status === 'OK') {359                    configurationCandidates = response.data;360                    return response.data.map(function (item) {361                        return item.name;362                    });363                } else {364                    configurationCandidates = [];365                    return [];366                }367            });368        };369        $scope.editRuleDevices = function () {370            var modalInstance = $modal.open({371                templateUrl: 'app/components/plugins/devicelog/views/ruleDevices.modal.html',372                controller: 'PluginDeviceLogEditRuleDevicesController',373                resolve: {374                    rule: function () {375                        return $scope.rule;376                    }377                }378            });379            modalInstance.result.then(function (ruleDevicesToUse) {380                $scope.rule.devices = ruleDevicesToUse;381            });382        };383        $scope.closeModal = function () {384            $modalInstance.dismiss();385        };386        $scope.save = function () {387            // Validate form388            if (!$scope.rule.name || $scope.rule.name.length === 0) {389                $scope.errorMessage = localization.localize('plugin.devicelog.settings.error.empty.rule.name');390            } else if (!$scope.rule.applicationPkg || $scope.rule.applicationPkg.length === 0) {391                $scope.errorMessage = localization.localize('plugin.devicelog.settings.error.empty.rule.app.pkg');392            } else if (!$scope.rule.severity || $scope.rule.severity.length === 0) {393                $scope.errorMessage = localization.localize('plugin.devicelog.settings.error.empty.rule.severity');394            } else if (!validateApplication()) {395                $scope.errorMessage = localization.localize('plugin.devicelog.settings.error.invalid.app');396            } else if (!validateGroup()) {397                $scope.errorMessage = localization.localize('plugin.devicelog.settings.error.invalid.group');398            } else if (!validateConfiguration()) {399                $scope.errorMessage = localization.localize('plugin.devicelog.settings.error.invalid.configuration');400            } else {401                $scope.saving = true;402                pluginDeviceLogService.saveSettingsRule($scope.rule, function (response) {403                    $scope.saving = false;404                    if (response.status === 'OK') {405                        $modalInstance.close(true);406                    } else {407                        $scope.errorMessage = localization.localize(response.message);408                    }409                }, function () {410                    $scope.saving = false;411                    $scope.errorMessage = localization.localize('error.request.failure');412                });413            }414        };415        var validateApplication = function () {416            if ($scope.rule.applicationPkg) {417                let foundItems = appCandidates.filter(function (item) {418                    return item.name === $scope.rule.applicationPkg;419                });420                if (foundItems.length > 0) {421                    $scope.rule.applicationId = foundItems[0].id;422                    return true;423                } else {424                    return false;425                }426            } else {427                $scope.rule.applicationId = null;428            }429            return true;430        };431        var validateGroup = function () {432            if ($scope.rule.groupName) {433                let foundItems = groupCandidates.filter(function (item) {434                    return item.name === $scope.rule.groupName;435                });436                if (foundItems.length > 0) {437                    $scope.rule.groupId = foundItems[0].id;438                    return true;439                } else {440                    return false;441                }442            } else {443                $scope.rule.groupId = null;444            }445            return true;446        };447        var validateConfiguration = function () {448            if ($scope.rule.configurationName) {449                let foundItems = configurationCandidates.filter(function (item) {450                    return item.name === $scope.rule.configurationName;451                });452                if (foundItems.length > 0) {453                    $scope.rule.configurationId = foundItems[0].id;454                    return true;455                } else {456                    return false;457                }458            } else {459                $scope.rule.configurationId = null;460            }461            return true;462        };463        if ($scope.rule.applicationPkg) {464            $scope.getApplications($scope.rule.applicationPkg);465        }466        if ($scope.rule.groupName) {467            $scope.getGroups($scope.rule.groupName);468        }469        if ($scope.rule.configurationName) {470            $scope.getConfigurations($scope.rule.configurationName);471        }472    })473    .controller('PluginDeviceLogEditRuleDevicesController', function ($scope, $modalInstance, $http,474                              localization, pluginDeviceLogService, rule) {475        var ruleCopy = {};476        for (var p in rule) {477            if (rule.hasOwnProperty(p)) {478                ruleCopy[p] = rule[p];479            }480        }481        ruleCopy.devices = [];482        if (rule.devices) {483            ruleCopy.devices = ruleCopy.devices.concat(rule.devices);484        }485        $scope.rule = ruleCopy;486        $scope.saving = false;487        $scope.newDevice = null;488        var deviceCandidates = [];489        $scope.addNewDevice = function () {490            $scope.errorMessage = undefined;491            if ($scope.newDevice) {492                let foundItems = deviceCandidates.filter(function (item) {493                    return item.name === $scope.newDevice;494                });495                if (foundItems.length > 0) {496                     $scope.rule.devices.push(foundItems[0]);497                     $scope.newDevice = null;498                     deviceCandidates = [];499                } else {500                    $scope.errorMessage = localization.localize('plugin.devicelog.settings.error.invalid.device');501                }502            }503        };504        $scope.getDevices = function(val) {505            return pluginDeviceLogService.lookupDevices(val).$promise.then(function(response){506                if (response.status === 'OK') {507                    deviceCandidates = response.data.filter(function (device) {508                        return $scope.rule.devices.findIndex(function (ruleDevice) {509                            return ruleDevice.id === device.id;510                        }) === -1;511                    });512                    return deviceCandidates.map(function (item) {513                        return item.name;514                    });515                } else {516                    deviceCandidates = [];517                    return [];518                }519            });520        };521        $scope.removeDevice = function (device) {522            var index = $scope.rule.devices.indexOf(device);523            if (index !== -1) {524                $scope.rule.devices.splice(index, 1);525            }526        };527        $scope.closeModal = function () {528            $modalInstance.dismiss();529        };530        $scope.save = function () {531            $modalInstance.close($scope.rule.devices);532        };533    })534    .run(function ($rootScope, $location, localization) {535        $rootScope.$on('plugin-devicelog-device-selected', function (event, device) {536            $location.url('/plugin-devicelog?deviceNumber=' + device.number);537        });538        localization.loadPluginResourceBundles("devicelog");...

Full Screen

Full Screen

ios-deploy.js

Source:ios-deploy.js Github

copy

Full Screen

...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 {...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const {remote} = require('webdriverio');2const opts = {3  capabilities: {4  }5};6(async () => {7  const client = await remote(opts);8  const apps = await client.execute('mobile: lookupApplications', {bundleIds: ['com.apple.Preferences']});9  console.log(apps);10  await client.deleteSession();11})();12const {remote} = require('webdriverio');13const opts = {14  capabilities: {

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2driver.init({3}).then(() => {4  return driver.execute('mobile: launchApp', { bundleId: 'com.apple.mobilesafari' });5}).then(() => {6  return driver.execute('mobile: lookupApplications', { bundleIds: ['com.apple.mobilesafari'] });7}).then((res) => {8  console.log(res);9}).catch((err) => {10  console.log(err);11});12{13    {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { remote } = require('webdriverio');2const opts = {3    capabilities: {4    }5};6async function main () {7    const client = await remote(opts);8    const apps = await client.execute('mobile: lookupApplications', {bundleIds: ['com.apple.Preferences', 'com.apple.mobilecal']});9    console.log(apps);10}11main();12[0-0] 2019-08-08T06:08:00.000Z INFO webdriver: DATA { capabilities:13   { alwaysMatch: { platformName: 'iOS', appium: [Object] },14     firstMatch: [ {} ] },15   { platformName: 'iOS',16     automationName: 'XCUITest' } }17[0-0] 2019-08-08T06:08:00.000Z INFO webdriver: COMMAND mobile: lookupApplications()18[0-0] 2019-08-08T06:08:00.000Z INFO webdriver: DATA { bundleIds: [ 'com.apple.Preferences', 'com.apple.mobilecal' ] }19[0-0] 2019-08-08T06:08:00.000Z INFO webdriver: RESULT {20    {

Full Screen

Using AI Code Generation

copy

Full Screen

1var webdriver = require('selenium-webdriver');2var By = webdriver.By;3var until = webdriver.until;4var driver = new webdriver.Builder()5    .forBrowser('chrome')6    .build();7driver.findElement(By.name('q')).sendKeys('webdriver');8driver.findElement(By.name('btnG')).click();9driver.wait(until.titleIs('webdriver - Google Search'), 1000);10driver.quit();11[Appium] Welcome to Appium v1.6.4 (REV 6c2a2c2b6d0d6f7f6b8c9b7d4e4e6d4f6b0ad6b4)

Full Screen

Using AI Code Generation

copy

Full Screen

1const wdio = require('webdriverio');2const options = {3    desiredCapabilities: {4    }5};6const client = wdio.remote(options);7client.init().then(() => {8    console.log('client initialized');9    return client.execute('mobile: lookupApplications');10})11    .then((result) => {12        console.log('result: ', result);13        return client.end();14    })15    .catch((err) => {16        console.log('Error: ', err);17        client.end();18    });

Full Screen

Using AI Code Generation

copy

Full Screen

1const wdio = require('webdriverio');2const { services } = require('appium-xcuitest-driver');3const { XCUITestDriver } = require('appium-xcuitest-driver');4const { XCUITestSimulatorDriver } = require('appium-xcuitest-driver');5const opts = {6    capabilities: {7    }8};9async function main () {10    const client = await wdio.remote(opts);11    const driver = new XCUITestDriver(opts);12    const service = new services.ApplicationsService(driver);13    const applications = await service.lookupApplications();14    console.log(applications);15    await client.deleteSession();16}17main();

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const chai = require('chai');3const chaiAsPromised = require('chai-as-promised');4const assert = chai.assert;5const expect = chai.expect;6const should = chai.should();7chai.use(chaiAsPromised);8const PORT = 4723;9const HOST = 'localhost';10const config = {11};12const driver = wd.promiseChainRemote(HOST, PORT);13describe('Appium XCUITest Driver', () => {14  before(async () => {15    await driver.init(config);16    await driver.sleep(5000);17  });18  it('should get the list of installed applications', async () => {19    const apps = await driver.execute('mobile: lookupApplications', {bundleIds: ['com.apple.mobilemail']});20    console.log(apps);21  });22  after(async () => {23    await driver.quit();24  });25});26  {27  }

Full Screen

Using AI Code Generation

copy

Full Screen

1const request = require('request');2request.post({3  json: {4    args: {}5  }6}, (err, res, body) => {7  console.log(body);8});9{ status: 0,10   [ { CFBundleIdentifier: 'com.apple.Preferences',11       version: '12.0' },12     { CFBundleIdentifier: 'com.apple.mobilesafari',13       version: '10.0' },14     { CFBundleIdentifier: 'com.apple.springboard',

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