How to use setLocaleAndPreferences method in Appium Xcuitest Driver

Best JavaScript code snippet using appium-xcuitest-driver

driver.js

Source:driver.js Github

copy

Full Screen

...294 // await this.sim.shutdown();295 await this.startHttpsAsyncServer();296 }297 await isolateSimulatorDevice(this.sim, this.opts);298 this.localConfig = await setLocaleAndPreferences(this.sim, this.opts, this.isSafari(), endSimulator);299 await this.setUpLogCapture();300 await this.prelaunchSimulator();301 await this.startInstruments();302 await this.onInstrumentsLaunch();303 await this.configureBootstrap();304 await this.setBundleId();305 await this.setInitialOrientation();306 await this.initAutoWebview();307 await this.waitForAppLaunched();308 }309 async startRealDevice () {310 await utils.removeInstrumentsSocket(this.sock);311 this.opts.localizableStrings = await utils.parseLocalizableStrings(this.opts);312 await utils.setBundleIdFromApp(this.opts);...

Full Screen

Full Screen

simulator-management.js

Source:simulator-management.js Github

copy

Full Screen

1import { getSimulator } from 'appium-ios-simulator';2import Simctl from 'node-simctl';3import { resetTestProcesses } from 'appium-webdriveragent';4import _ from 'lodash';5import log from './logger';6import { util } from '@appium/support';7import { PLATFORM_NAME_IOS } from './desired-caps';8const APPIUM_SIM_PREFIX = 'appiumTest';9const SETTINGS_CAPS = [10 'locationServicesEnabled',11 'locationServicesAuthorized',12];13const SAFARI_SETTINGS_CAPS = [14 'safariAllowPopups',15 'safariIgnoreFraudWarning',16 'safariOpenLinksInBackground',17];18/**19 * Capability set by a user20 *21 * @property {string} deviceName - A name for the device22 * @property {string} platformVersion - The version of iOS to use23 */24/**25 * Create a new simulator with `appiumTest-` prefix and return the object.26 *27 * @param {object} SimCreationCaps - Capability set by a user. The options available are:28 * @property {string} platform [iOS] - Platform name in order to specify runtime such as 'iOS', 'tvOS', 'watchOS'29 * @returns {object} Simulator object associated with the udid passed in.30 */31async function createSim (caps, platform = PLATFORM_NAME_IOS) {32 const devicesSetPath = caps.simulatorDevicesSetPath;33 const udid = await new Simctl({devicesSetPath}).createDevice(34 `${APPIUM_SIM_PREFIX}-${util.uuidV4().toUpperCase()}-${caps.deviceName}`,35 caps.deviceName,36 caps.platformVersion,37 {platform},38 );39 return await getSimulator(udid, {40 platform,41 checkExistence: false,42 devicesSetPath,43 });44}45/**46 * @typedef {Object} SimulatorLookupOptions47 * @property {!string} deviceName - The name of the device to lookup48 * @property {!string} platformVersion - The platform version string49 * @property {?string} simulatorDevicesSetPath - The full path to the simulator devices set50 */51/**52 * Get a simulator which is already running.53 *54 * @param {?SimulatorLookupOptions} opts55 * @returns {?Simulator} The matched Simulator instance or `null` if no matching device is found.56 */57async function getExistingSim (opts = {}) {58 const {59 platformVersion,60 deviceName,61 simulatorDevicesSetPath: devicesSetPath,62 } = opts;63 let appiumTestDevice;64 const simctl = new Simctl({devicesSetPath});65 for (const device of _.values(await simctl.getDevices(platformVersion))) {66 if (device.name === deviceName) {67 return await getSimulator(device.udid, {68 platform: device.platform,69 checkExistence: false,70 devicesSetPath,71 });72 }73 if (device.name.startsWith(APPIUM_SIM_PREFIX) && device.name.endsWith(deviceName)) {74 appiumTestDevice = device;75 // choose the first booted simulator76 if (device.state === 'Booted') {77 break;78 }79 }80 }81 if (appiumTestDevice) {82 log.warn(`Unable to find device '${deviceName}'. ` +83 `Found '${appiumTestDevice.name}' (udid: '${appiumTestDevice.udid}') instead`);84 return await getSimulator(appiumTestDevice.udid, {85 platform: appiumTestDevice.platform,86 checkExistence: false,87 devicesSetPath,88 });89 }90 return null;91}92async function shutdownSimulator (device) {93 // stop XCTest processes if running to avoid unexpected side effects94 await resetTestProcesses(device.udid, true);95 await device.shutdown();96}97async function runSimulatorReset (device, opts) {98 if (opts.noReset && !opts.fullReset) {99 // noReset === true && fullReset === false100 log.debug('Reset: noReset is on. Leaving simulator as is');101 return;102 }103 if (!device) {104 log.debug('Reset: no device available. Skipping');105 return;106 }107 if (opts.fullReset) {108 log.debug('Reset: fullReset is on. Cleaning simulator');109 await shutdownSimulator(device);110 let isKeychainsBackupSuccessful = false;111 if (opts.keychainsExcludePatterns || opts.keepKeyChains) {112 isKeychainsBackupSuccessful = await device.backupKeychains();113 }114 await device.clean();115 if (isKeychainsBackupSuccessful) {116 await device.restoreKeychains(opts.keychainsExcludePatterns || []);117 log.info(`Successfully restored keychains after full reset`);118 } else if (opts.keychainsExcludePatterns || opts.keepKeyChains) {119 log.warn('Cannot restore keychains after full reset, because ' +120 'the backup operation did not succeed');121 }122 } else if (opts.bundleId) {123 // fastReset or noReset124 // Terminate the app under test if it is still running on Simulator125 // Termination is not needed if Simulator is not running126 if (await device.isRunning()) {127 if (opts.enforceSimulatorShutdown) {128 await shutdownSimulator(device);129 } else {130 try {131 await device.simctl.terminateApp(opts.bundleId);132 } catch (err) {133 log.warn(`Reset: failed to terminate Simulator application with id "${opts.bundleId}"`);134 }135 }136 }137 if (opts.app) {138 log.info('Not scrubbing third party app in anticipation of uninstall');139 return;140 }141 const isSafari = (opts.browserName || '').toLowerCase() === 'safari';142 try {143 if (isSafari) {144 await device.cleanSafari();145 } else {146 // iOS 8+ does not need basename147 await device.scrubCustomApp('', opts.bundleId);148 }149 } catch (err) {150 log.warn(err.message);151 log.warn(`Reset: could not scrub ${isSafari ? 'Safari browser' : 'application with id "' + opts.bundleId + '"'}. Leaving as is.`);152 }153 }154}155/**156 * @typedef {Object} InstallOptions157 *158 * @property {?boolean} noReset [false] Whether to disable reset159 * @property {?boolean} newSimulator [false] Whether the simulator is brand new160 */161/**162 * @param {object} device The simulator device object163 * @param {?string} app The app to the path164 * @param {string} bundleId The bundle id to ensure it is already installed and uninstall it165 * @param {?InstallOptions} opts166 */167async function installToSimulator (device, app, bundleId, opts = {}) {168 if (!app) {169 log.debug('No app path is given. Nothing to install.');170 return;171 }172 const {173 noReset = true,174 newSimulator = false,175 } = opts;176 if (!newSimulator && bundleId && await device.isAppInstalled(bundleId)) {177 if (noReset) {178 log.debug(`App '${bundleId}' is already installed. No need to reinstall.`);179 return;180 }181 log.debug(`Reset requested. Removing app with id '${bundleId}' from the device`);182 await device.removeApp(bundleId);183 }184 log.debug(`Installing '${app}' on Simulator with UUID '${device.udid}'...`);185 try {186 await device.installApp(app);187 } catch (e) {188 // it sometimes fails on Xcode 10 because of a race condition189 log.info(`Got an error on '${app}' install: ${e.message}`);190 log.info('Retrying application install');191 await device.installApp(app);192 }193 log.debug('The app has been installed successfully.');194}195async function shutdownOtherSimulators (currentDevice) {196 const simctl = new Simctl({197 devicesSetPath: currentDevice.devicesSetPath198 });199 const allDevices = _.flatMap(_.values(await simctl.getDevices()));200 const otherBootedDevices = allDevices.filter((device) => device.udid !== currentDevice.udid && device.state === 'Booted');201 if (_.isEmpty(otherBootedDevices)) {202 log.info('No other running simulators have been detected');203 return;204 }205 log.info(`Detected ${otherBootedDevices.length} other running ${util.pluralize('Simulator', otherBootedDevices.length)}.` +206 `Shutting them down...`);207 for (const {udid} of otherBootedDevices) {208 // It is necessary to stop the corresponding xcodebuild process before killing209 // the simulator, otherwise it will be automatically restarted210 await resetTestProcesses(udid, true);211 simctl.udid = udid;212 await simctl.shutdownDevice();213 }214}215async function launchAndQuitSimulator (sim, opts = {}) {216 log.debug('No simulator directories found.');217 const { safari, timeout } = opts;218 return timeout219 ? await sim.launchAndQuit(safari, timeout)220 : await sim.launchAndQuit(safari);221}222function checkPreferences (settings, opts = {}) {223 for (let setting of settings) {224 if (_.has(opts, setting)) {225 return true;226 }227 }228 return false;229}230async function setLocaleAndPreferences (sim, opts, safari = false, shutdownFn = _.noop) {231 const localConfig = await setLocale(sim, opts, {}, safari);232 const prefsUpdated = await setPreferences(sim, opts, safari);233 if (localConfig._updated || prefsUpdated) {234 log.debug('Updated settings. Rebooting the simulator if it is already open');235 await shutdownFn(sim);236 } else {237 log.debug('Setting did not need to be updated');238 }239 delete localConfig._updated;240 return localConfig;241}242// pass in the simulator so that other systems that use the function can supply243// whatever they have244async function setLocale (sim, opts, localeConfig = {}, safari = false) {245 if (!opts.language && !opts.locale && !opts.calendarFormat) {246 log.debug('No reason to set locale');247 return {248 _updated: false,249 };250 }251 // we need the simulator to have its directories in place252 if (await sim.isFresh()) {253 await launchAndQuitSimulator(sim, {254 safari,255 timeout: opts.simulatorStartupTimeout,256 });257 }258 log.debug('Setting locale information');259 localeConfig = {260 language: opts.language || localeConfig.language,261 locale: opts.locale || localeConfig.locale,262 calendarFormat: opts.calendarFormat || localeConfig.calendarFormat,263 _updated: false,264 };265 try {266 let updated = await sim.updateLocale(opts.language, opts.locale, opts.calendarFormat);267 if (updated) {268 localeConfig._updated = true;269 }270 } catch (e) {271 log.errorAndThrow(`Appium was unable to set locale info: ${e}`);272 }273 return localeConfig;274}275async function setPreferences (sim, opts, safari = false) {276 let needToSetPrefs = checkPreferences(SETTINGS_CAPS, opts);277 let needToSetSafariPrefs = checkPreferences(SAFARI_SETTINGS_CAPS, opts);278 if (!needToSetPrefs && !needToSetSafariPrefs) {279 log.debug('No iOS / app preferences to set');280 return false;281 }282 log.debug('Setting iOS and app preferences');283 if (await sim.isFresh()) {284 await launchAndQuitSimulator(sim, {285 safari,286 timeout: opts.simulatorStartupTimeout,287 });288 }289 let updated = false;290 try {291 if (needToSetPrefs) {292 updated = await setLocServicesPrefs(sim, opts);293 }294 } catch (e) {295 log.error('Error setting location services preferences, prefs will not work');296 log.error(e);297 }298 try {299 if (needToSetSafariPrefs) {300 updated = await setSafariPrefs(sim, opts) || updated;301 }302 } catch (e) {303 log.error('Error setting safari preferences, prefs will not work');304 log.error(e);305 }306 return updated;307}308async function setLocServicesPrefs (sim, opts = {}) {309 let locServ = _.find([opts.locationServicesEnabled, opts.locationServicesAuthorized], (c) => !_.isUndefined(c));310 if (!_.isUndefined(locServ)) {311 locServ = locServ ? 1 : 0;312 log.debug(`Setting location services to ${locServ}`);313 await sim.updateSettings('locationServices', {314 LocationServicesEnabled: locServ,315 'LocationServicesEnabledIn7.0': locServ,316 'LocationServicesEnabledIn8.0': locServ317 });318 }319 if (!_.isUndefined(opts.locationServicesAuthorized)) {320 if (!opts.bundleId) {321 let msg = "Can't set location services for app without bundle ID";322 log.errorAndThrow(msg);323 }324 let locAuth = !!opts.locationServicesAuthorized;325 if (locAuth) {326 log.debug('Authorizing location services for app');327 } else {328 log.debug('De-authorizing location services for app');329 }330 await sim.updateLocationSettings(opts.bundleId, locAuth);331 }332}333async function setSafariPrefs (sim, opts = {}) {334 let safariSettings = {};335 if (_.has(opts, 'safariAllowPopups')) {336 const val = !!opts.safariAllowPopups;337 log.debug(`Setting javascript window opening to '${val}'`);338 safariSettings.WebKitJavaScriptCanOpenWindowsAutomatically = val;339 safariSettings.JavaScriptCanOpenWindowsAutomatically = val;340 }341 if (_.has(opts, 'safariIgnoreFraudWarning')) {342 const val = !opts.safariIgnoreFraudWarning;343 log.debug(`Setting fraudulent website warning to '${val}'`);344 safariSettings.WarnAboutFraudulentWebsites = val;345 }346 if (_.has(opts, 'safariOpenLinksInBackground')) {347 const val = opts.safariOpenLinksInBackground ? 1 : 0;348 log.debug(`Setting opening links in background to '${!!val}'`);349 safariSettings.OpenLinksInBackground = val;350 }351 return (_.size(safariSettings) > 0)352 ? await sim.updateSafariSettings(safariSettings)353 : false;354}355export {356 createSim, getExistingSim, runSimulatorReset, installToSimulator,357 shutdownSimulator, shutdownOtherSimulators,358 setLocale, setPreferences, setLocaleAndPreferences,...

Full Screen

Full Screen

driver-specs.js

Source:driver-specs.js Github

copy

Full Screen

1import sinon from 'sinon';2import { JWProxy } from '@appium/base-driver';3import XCUITestDriver from '../..';4import * as simSettings from '../../lib/simulator-management';5import * as appUtils from '../../lib/app-utils';6import xcode from 'appium-xcode';7import _ from 'lodash';8import chai from 'chai';9import B from 'bluebird';10import * as utils from '../../lib/utils';11import { MOCHA_LONG_TIMEOUT } from './helpers';12chai.should();13const expect = chai.expect;14const caps = {15 fistMatch: [{}],16 alwaysMatch: {17 platformName: 'iOS',18 'appium:deviceName': 'iPhone 6',19 'appium:app': '/foo.app',20 'appium:platformVersion': '10.0',21 }22};23describe('getDefaultUrl', function () {24 let driver;25 beforeEach(function () {26 driver = new XCUITestDriver();27 });28 it('real device', function () {29 driver.opts.realDevice = true;30 expect(driver.getDefaultUrl()).eq('http://appium.io');31 });32 it('simulator with ipv4', function () {33 driver.opts.realDevice = false;34 driver.opts.address = '127.0.0.1';35 driver.opts.port = '8080';36 expect(driver.getDefaultUrl()).eq('http://127.0.0.1:8080/welcome');37 });38 it('simulator with ipv6', function () {39 driver.opts.realDevice = false;40 driver.opts.address = '::1';41 driver.opts.port = '8080';42 expect(driver.getDefaultUrl()).eq('http://[::1]:8080/welcome');43 });44});45describe('driver commands', function () {46 describe('status', function () {47 let driver;48 let jwproxyCommandSpy;49 beforeEach(function () {50 driver = new XCUITestDriver();51 // fake the proxy to WDA52 const jwproxy = new JWProxy();53 jwproxyCommandSpy = sinon.stub(jwproxy, 'command').callsFake(async function () { // eslint-disable-line require-await54 return {some: 'thing'};55 });56 driver.wda = {57 jwproxy,58 };59 });60 afterEach(function () {61 jwproxyCommandSpy.reset();62 });63 it('should not have wda status by default', async function () {64 const status = await driver.getStatus();65 jwproxyCommandSpy.calledOnce.should.be.false;66 expect(status.wda).to.be.undefined;67 });68 it('should return wda status if cached', async function () {69 driver.cachedWdaStatus = {};70 const status = await driver.getStatus();71 jwproxyCommandSpy.called.should.be.false;72 status.wda.should.exist;73 });74 });75 describe('createSession', function () {76 let driver;77 let sandbox;78 beforeEach(function () {79 driver = new XCUITestDriver();80 sandbox = sinon.createSandbox();81 sandbox.stub(driver, 'determineDevice').callsFake(async function () { // eslint-disable-line require-await82 return {83 device: {84 shutdown: _.noop,85 isRunning () {86 return true;87 },88 stat () {89 return {state: 'Booted'};90 },91 clearCaches: _.noop,92 getWebInspectorSocket () {93 return '/path/to/uds.socket';94 },95 },96 udid: null,97 realDevice: null98 };99 });100 sandbox.stub(driver, 'configureApp').callsFake(_.noop);101 sandbox.stub(driver, 'startLogCapture').callsFake(_.noop);102 sandbox.stub(driver, 'startSim').callsFake(_.noop);103 sandbox.stub(driver, 'startWdaSession').callsFake(_.noop);104 sandbox.stub(driver, 'startWda').callsFake(_.noop);105 sandbox.stub(driver, 'setReduceMotion').callsFake(_.noop);106 sandbox.stub(driver, 'installAUT').callsFake(_.noop);107 sandbox.stub(driver, 'connectToRemoteDebugger').callsFake(_.noop);108 sandbox.stub(simSettings, 'setLocaleAndPreferences').callsFake(_.noop);109 sandbox.stub(xcode, 'getMaxIOSSDK').callsFake(async () => '10.0'); // eslint-disable-line require-await110 sandbox.stub(utils, 'checkAppPresent').callsFake(_.noop);111 sandbox.stub(appUtils, 'extractBundleId').callsFake(_.noop);112 });113 afterEach(function () {114 sandbox.restore();115 });116 it('should include server capabilities', async function () {117 this.timeout(MOCHA_LONG_TIMEOUT);118 const resCaps = await driver.createSession(null, null, _.cloneDeep(caps));119 resCaps[1].javascriptEnabled.should.be.true;120 });121 it('should call startLogCapture', async function () {122 this.timeout(MOCHA_LONG_TIMEOUT);123 const resCaps = await driver.createSession(null, null, _.merge({}, caps, {124 alwaysMatch: {125 'appium:skipLogCapture': false,126 }127 }));128 resCaps[1].javascriptEnabled.should.be.true;129 driver.startLogCapture.called.should.be.true;130 });131 it('should not call startLogCapture', async function () {132 this.timeout(MOCHA_LONG_TIMEOUT);133 const resCaps = await driver.createSession(null, null, _.merge({}, caps, {134 alwaysMatch: {135 'appium:skipLogCapture': true,136 }137 }));138 resCaps[1].javascriptEnabled.should.be.true;139 driver.startLogCapture.called.should.be.false;140 });141 });142});143describe('installOtherApps', function () {144 let driver = new XCUITestDriver();145 let sandbox;146 beforeEach(function () {147 sandbox = sinon.createSandbox();148 });149 afterEach(function () {150 sandbox.restore();151 });152 it('should skip install other apps on real devices', async function () {153 sandbox.stub(driver, 'isRealDevice');154 sandbox.stub(driver.helpers, 'parseCapsArray');155 driver.isRealDevice.returns(true);156 await driver.installOtherApps('/path/to/iosApp.app');157 driver.isRealDevice.calledOnce.should.be.true;158 driver.helpers.parseCapsArray.notCalled.should.be.true;159 });160 it('should install multiple apps from otherApps as string on simulators', async function () {161 const SimulatorManagementModule = require('../../lib/simulator-management');162 sandbox.stub(SimulatorManagementModule, 'installToSimulator');163 sandbox.stub(driver, 'isRealDevice');164 driver.isRealDevice.returns(false);165 sandbox.stub(driver.helpers, 'configureApp');166 driver.helpers.configureApp.returns(B.resolve('/path/to/iosApp.app'));167 driver.opts.noReset = false;168 driver.opts.device = 'some-device';169 driver.lifecycleData = {createSim: false};170 await driver.installOtherApps('/path/to/iosApp.app');171 driver.isRealDevice.calledOnce.should.be.true;172 driver.helpers.configureApp.calledOnce.should.be.true;173 SimulatorManagementModule.installToSimulator.calledOnce.should.be.true;174 SimulatorManagementModule.installToSimulator.calledWith(175 'some-device',176 '/path/to/iosApp.app',177 undefined, {noReset: false, newSimulator: false}178 ).should.be.true;179 });180 it('should install multiple apps from otherApps as JSON array on simulators', async function () {181 const SimulatorManagementModule = require('../../lib/simulator-management');182 sandbox.stub(SimulatorManagementModule, 'installToSimulator');183 sandbox.stub(driver, 'isRealDevice');184 driver.isRealDevice.returns(false);185 sandbox.stub(driver.helpers, 'configureApp');186 driver.helpers.configureApp.onCall(0).returns(B.resolve('/path/to/iosApp1.app'));187 driver.helpers.configureApp.onCall(1).returns(B.resolve('/path/to/iosApp2.app'));188 driver.opts.noReset = false;189 driver.opts.device = 'some-device';190 driver.lifecycleData = {createSim: false};191 await driver.installOtherApps('["/path/to/iosApp1.app","/path/to/iosApp2.app"]');192 driver.isRealDevice.calledOnce.should.be.true;193 driver.helpers.configureApp.calledTwice.should.be.true;194 SimulatorManagementModule.installToSimulator.calledWith(195 'some-device',196 '/path/to/iosApp1.app',197 undefined, {noReset: false, newSimulator: false}198 ).should.be.true;199 SimulatorManagementModule.installToSimulator.calledWith(200 'some-device',201 '/path/to/iosApp2.app',202 undefined, {noReset: false, newSimulator: false}203 ).should.be.true;204 });...

Full Screen

Full Screen

settings.js

Source:settings.js Github

copy

Full Screen

1import _ from 'lodash';2import logger from './logger';3const SETTINGS_CAPS = [4 'locationServicesEnabled',5 'locationServicesAuthorized',6];7const SAFARI_SETTINGS_CAPS = [8 'safariAllowPopups',9 'safariIgnoreFraudWarning',10 'safariOpenLinksInBackground',11];12async function launchAndQuitSimulator (sim, safari) {13 logger.debug('No simulator directories found.');14 return await sim.launchAndQuit(safari);15}16function checkPreferences (settings, opts = {}) {17 for (let setting of settings) {18 if (_.has(opts, setting)) {19 return true;20 }21 }22 return false;23}24async function setLocaleAndPreferences (sim, opts, safari = false, shutdownFn = _.noop) {25 const localConfig = await setLocale(sim, opts, {}, safari);26 const prefsUpdated = await setPreferences(sim, opts, safari);27 if (localConfig._updated || prefsUpdated) {28 logger.debug("Updated settings. Rebooting the simulator if it's already open");29 await shutdownFn(sim);30 }31 delete localConfig._updated;32 return localConfig;33}34// pass in the simulator so that other systems that use the function can supply35// whatever they have36async function setLocale (sim, opts, localeConfig = {}, safari = false) {37 if (!opts.language && !opts.locale && !opts.calendarFormat) {38 logger.debug("No reason to set locale");39 return {40 _updated: false,41 };42 }43 // we need the simulator to have its directories in place44 if (await sim.isFresh()) {45 await launchAndQuitSimulator(sim, safari);46 }47 logger.debug('Setting locale information');48 localeConfig = {49 language: opts.language || localeConfig.language,50 locale: opts.locale || localeConfig.locale,51 calendarFormat: opts.calendarFormat || localeConfig.calendarFormat,52 _updated: false,53 };54 try {55 let updated = await sim.updateLocale(opts.language, opts.locale, opts.calendarFormat);56 if (updated) {57 localeConfig._updated = true;58 }59 } catch (e) {60 logger.errorAndThrow(`Appium was unable to set locale info: ${e}`);61 }62 return localeConfig;63}64async function setPreferences (sim, opts, safari = false) {65 let needToSetPrefs = checkPreferences(SETTINGS_CAPS, opts);66 let needToSetSafariPrefs = checkPreferences(SAFARI_SETTINGS_CAPS, opts);67 if (!needToSetPrefs && !needToSetSafariPrefs) {68 logger.debug("No iOS / app preferences to set");69 return false;70 }71 logger.debug("Setting iOS and app preferences");72 if (await sim.isFresh()) {73 await launchAndQuitSimulator(sim, safari);74 }75 try {76 if (needToSetPrefs) {77 await setLocServicesPrefs(sim, opts);78 }79 } catch (e) {80 logger.error("Error setting location services preferences, prefs will not work");81 logger.error(e);82 }83 try {84 if (needToSetSafariPrefs) {85 await setSafariPrefs(sim, opts);86 }87 } catch (e) {88 logger.error("Error setting safari preferences, prefs will not work");89 logger.error(e);90 }91 return true;92}93async function setLocServicesPrefs (sim, opts = {}) {94 let locServ = _.find([opts.locationServicesEnabled, opts.locationServicesAuthorized], (c) => {95 return !_.isUndefined(c);96 });97 if (!_.isUndefined(locServ)) {98 locServ = locServ ? 1 : 0;99 logger.debug(`Setting location services to ${locServ}`);100 await sim.updateSettings('locationServices', {101 LocationServicesEnabled: locServ,102 'LocationServicesEnabledIn7.0': locServ,103 'LocationServicesEnabledIn8.0': locServ104 });105 }106 if (!_.isUndefined(opts.locationServicesAuthorized)) {107 if (!opts.bundleId) {108 let msg = "Can't set location services for app without bundle ID";109 logger.errorAndThrow(msg);110 }111 let locAuth = !!opts.locationServicesAuthorized;112 if (locAuth) {113 logger.debug("Authorizing location services for app");114 } else {115 logger.debug("De-authorizing location services for app");116 }117 await sim.updateLocationSettings(opts.bundleId, locAuth);118 }119}120async function setSafariPrefs (sim, opts = {}) {121 let safariSettings = {};122 if (_.has(opts, 'safariAllowPopups')) {123 let val = !!opts.safariAllowPopups;124 logger.debug(`Setting javascript window opening to '${val}'`);125 safariSettings.WebKitJavaScriptCanOpenWindowsAutomatically = val;126 safariSettings.JavaScriptCanOpenWindowsAutomatically = val;127 }128 if (_.has(opts, 'safariIgnoreFraudWarning')) {129 let val = !opts.safariIgnoreFraudWarning;130 logger.debug(`Setting fraudulent website warning to '${val}'`);131 safariSettings.WarnAboutFraudulentWebsites = val;132 }133 if (_.has(opts, 'safariOpenLinksInBackground')) {134 let val = opts.safariOpenLinksInBackground ? 1 : 0;135 logger.debug(`Setting opening links in background to '${!!val}'`);136 safariSettings.OpenLinksInBackground = val;137 }138 if (_.size(safariSettings) > 0) {139 await sim.updateSafariSettings(safariSettings);140 }141}...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1const wdio = require("webdriverio");2const opts = {3 capabilities: {4 }5};6async function main() {7 const client = await wdio.remote(opts);8 await client.setLocaleAndPreferences({9 locale: {10 },11 timeZone: {12 }13 });14 await client.deleteSession();15}16main();17opts = {18 caps: {19 }20}21Appium::Driver.new(opts).start_driver22Appium::TouchAction.new.set_locale_and_preferences({23 locale: {24 },25 timeZone: {26 }27})28Appium::Driver.new(opts).quit_driver29from appium import webdriver

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 await client.setLocaleAndPreferences({9 });10}11main();12{13 "scripts": {14 },15 "dependencies": {16 }17}18const { remote } = require('webdriverio');19const opts = {20 capabilities: {21 }22};23async function main () {24 const client = await remote(opts);25 await client.setLocaleAndPreferences({

Full Screen

Using AI Code Generation

copy

Full Screen

1const { remote } = require('webdriverio');2(async () => {3 const browser = await remote({4 capabilities: {5 setLocaleAndPreferences: {6 locale: {7 },8 calendar: {9 },10 timeZone: {11 },12 dateFormat: {13 },14 keyboard: {15 }16 }17 }18 });19 await browser.deleteSession();20})();21from appium import webdriver22caps = {23 'setLocaleAndPreferences': {24 'locale': {25 },26 'calendar': {27 },28 'timeZone': {29 },30 'dateFormat': {31 },32 'keyboard': {33 }34 }35}36driver.quit()37import io.appium.java_client

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const path = require('path');3const { exec } = require('teen_process');4const { fs, logger, util } = require('appium-support');5const log = logger.getLogger('iOSTest');6const SIM_DEVICE_NAME = 'iPhone 8';7const SIM_UDID = 'E9A9C8A8-0F0C-4A3B-9A70-3F2D2B7B9C9E';8const SIM_PLATFORM_VERSION = '12.2';9async function main () {10 const caps = {11 app: path.resolve('path/to/app'),12 };13 await driver.init(caps);14 await driver.setLocaleAndPreferences({15 });16 await driver.quit();17}18main().catch((err) => {19 log.errorAndThrow(err);20});21{22 "scripts": {23 },24 "dependencies": {25 }26}27{28 "dependencies": {29 "appium-support": {

Full Screen

Using AI Code Generation

copy

Full Screen

1const wdio = require('webdriverio');2const opts = {3 capabilities: {4 }5};6async function main () {7 const client = await wdio.remote(opts);8 await client.setLocaleAndPreferences('en_US', {calendar: 'gregorian'});9}10main();11const wdio = require('webdriverio');12const opts = {13 capabilities: {14 }15};16async function main () {17 const client = await wdio.remote(opts);18 await client.setLocaleAndPreferences('en_US', {calendar: 'gregorian'});19}20main();21const wdio = require('webdriverio');22const opts = {23 capabilities: {24 }25};26async function main () {27 const client = await wdio.remote(opts);28 await client.setLocaleAndPreferences('en_US', {calendar: 'gregorian'});29}30main();

Full Screen

Using AI Code Generation

copy

Full Screen

1const wd = require('wd');2const path = require('path');3const { exec } = require('teen_process');4const { fs, logger, util } = require('appium-support');5const log = logger.getLogger('iOSTest');6const SIM_DEVICE_NAME = 'iPhone 8';7const SIM_UDID = 'E9A9C8A8-0F0C-4A3B-9A70-3F2D2B7B9C9E';8const SIM_PLATFORM_VERSION = '12.2';9async function main () {10 const caps = {11 app: path.resolve('path/to/app'),12 };13 await driver.init(caps);14 await driver.setLocaleAndPreferences({15 });16 await driver.quit();17}18main().catch((err) => {19 log.errorAndThrow(err);20});21{22 "scripts": {23 },24 "dependencies": {25 }26}27{28 "dependencies": {29 "appium-support": {

Full Screen

Using AI Code Generation

copy

Full Screen

1const { remote } = require('webdriverio');2(async () => {3 const browser = await remote({4 capabilities: {5 setLocaleAndPreferences: {6 locale: {7 },8 calendar: {9 },10 timeZone: {11 },12 dateFormat: {13 },14 keyboard: {15 }16 }17 }18 });19 await browser.deleteSession();20})();21from appium import webdriver22caps = {23 'setLocaleAndPreferences': {24 'locale': {25 },26 'calendar': {27 },28 'timeZone': {29 },30 'dateFormat': {31 },32 'keyboard': {33 }34 }35}36driver.quit()37import io.appium.java_client

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 .setLocaleAndPreferences('en_US', {8 })9 .quit();

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