From b7e706a93f348769101f656d78677c916c2bb8e9 Mon Sep 17 00:00:00 2001 From: Jonathan Lipps Date: Mon, 20 Jan 2014 16:59:52 -0800 Subject: [PATCH] allow enabling/disabling locationservices via caps --- docs/caps.md | 1 + lib/devices/ios/ios.js | 18 ++++++++++++++++++ lib/devices/ios/settings.js | 4 +--- test/functional/prefs/prefs.js | 23 +++++++++++++++++++++++ 4 files changed, 43 insertions(+), 3 deletions(-) diff --git a/docs/caps.md b/docs/caps.md index 854478fe0..65399e535 100644 --- a/docs/caps.md +++ b/docs/caps.md @@ -33,5 +33,6 @@ Appium server capabilities |`language`| Language to set for the iOS Simulator|e.g. `fr`| |`launchTimeout`| Amount of time in ms to wait for instruments before assuming it hung and failing the session|e.g. `20000`| |`locale`| Locale to set for the iOS Simulator|e.g. `fr_CA`| +|`locationServicesEnabled`| Force location services to be either on or off|`true` or `false`| |`autoAcceptAlerts`| Accept iOS privacy access permission alerts (e.g., location, contacts, photos). Default is false.| |`nativeInstrumentsLib`| Use native intruments lib (ie disable instruments-without-delay).| diff --git a/lib/devices/ios/ios.js b/lib/devices/ios/ios.js index 1f24777bc..d363025d4 100644 --- a/lib/devices/ios/ios.js +++ b/lib/devices/ios/ios.js @@ -23,6 +23,7 @@ var path = require('path') , async = require('async') , iOSController = require('./ios-controller.js') , iOSHybrid = require('./ios-hybrid.js') + , settings = require('./settings.js') , UnknownError = errors.UnknownError; // XML Plist library helper @@ -194,6 +195,7 @@ IOS.prototype.start = function(cb, onDie) { this.detectUdid.bind(this), this.parseLocalizableStrings.bind(this), this.setLocale.bind(this), + this.setPreferences.bind(this), this.startLogCapture.bind(this), this.setDeviceAndLaunchSimulator.bind(this), this.installToRealDevice.bind(this), @@ -405,6 +407,22 @@ IOS.prototype.setLocale = function(cb) { } }; +IOS.prototype.setPreferences = function(cb) { + logger.info("Setting iOS and app preferences"); + var err = null; + if (typeof this.capabilities.locationServicesEnabled !== "undefined") { + var locServ = this.capabilities.locationServicesEnabled ? 1 : 0; + logger.info("Setting location services to " + locServ); + try { + settings.updateSettings(this.iOSSDKVersion, 'locationServices', + {LocationServicesEnabled: locServ}); + } catch (e) { + err = e; + } + } + cb(err); +}; + IOS.prototype.detectTraceTemplate = function(cb) { var msg; if (!this.automationTraceTemplatePath) { diff --git a/lib/devices/ios/settings.js b/lib/devices/ios/settings.js index a8e9e95ff..41e728f32 100644 --- a/lib/devices/ios/settings.js +++ b/lib/devices/ios/settings.js @@ -49,12 +49,10 @@ var prefs = { var getPlistPath = function(plist, sdk) { var file = plists[plist]; - console.log(file); var base = getPrefsDir(sdk); if (plist === 'mobileSafari' && parseFloat(sdk) >= 7) { base = getSafari7Dir(sdk); } - console.log(base); return path.resolve(base, file); }; @@ -118,7 +116,7 @@ var checkValidSettings = function(forPlist, prefSet) { }; settings.writeSettings = function(sdk, forPlist, prefSet, bypassCheck) { - logger.info("Writing settings for " + forPlist); + logger.info("Writing settings for " + forPlist + ":"); logger.info(JSON.stringify(prefSet)); if (!bypassCheck) { checkValidSettings(forPlist, prefSet); diff --git a/test/functional/prefs/prefs.js b/test/functional/prefs/prefs.js index a2528ec10..0604d4013 100644 --- a/test/functional/prefs/prefs.js +++ b/test/functional/prefs/prefs.js @@ -33,3 +33,26 @@ describeWd('settings app', function(h) { }).nodeify(done); }); }); + +var checkLocServ = function(h, expected, cb) { + h.driver + .execute("mobile: findAndAct", [{strategy: "tag name", selector: "tableCell", index: 2}]) + .sleep(1000) + .execute("mobile: findAndAct", [{strategy: "tag name", selector: "tableCell", index: 0}]) + .elementByTagName('switch') + .getValue().then(function(checked) { + checked.should.eql(expected); + }).nodeify(cb); +}; + +describeWd('settings app with location services', function(h) { + it('should respond to positive locationServicesEnabled cap', function(done) { + checkLocServ(h, 1, done); + }); +}, null, null, {locationServicesEnabled: true}); + +describeWd('settings app without location services', function(h) { + it('should respond to negative locationServicesEnabled cap', function(done) { + checkLocServ(h, 0, done); + }); +}, null, null, {locationServicesEnabled: false});