Merge pull request #2522 from rgonalo/ios-wrongid

Fix iOS callback problem after finding an element by a wrong id
This commit is contained in:
Jonathan Lipps
2014-05-12 01:31:11 -07:00
2 changed files with 13 additions and 2 deletions

View File

@@ -88,7 +88,7 @@ iOSController.findUIElementOrElements = function (strategy, selector, ctx, many,
try {
selector = this.getSelectorForStrategy(strategy, selector);
} catch (e) {
cb(null, {
return cb(null, {
status: status.codes.UnknownError.code
, value: e
});
@@ -230,7 +230,12 @@ iOSController.getSelectorForStrategy = function (strategy, selector) {
var newSelector = selector;
if (strategy === "id") {
var strings = this.localizableStrings;
if (strings && strings.length >= 1) newSelector = strings[0][selector];
if (strings && strings.length >= 1) {
newSelector = strings[0][selector];
if (!newSelector) {
throw new TypeError("Id selector not found in Localizable.strings.");
}
}
}
if (strategy === 'class name') {
if (selector.indexOf('UIA') !== 0) {

View File

@@ -69,6 +69,12 @@ describe('ios-controller', function () {
var actual = controller.getSelectorForStrategy('id', 'someSelector');
actual.should.equal('localSelector');
});
it('returns an error when the selector isn\'t in localizableStrings', function () {
var msg = "Id selector not found in Localizable.strings.";
(function () {
controller.getSelectorForStrategy('id', 'notFoundSelector');
}).should.Throw(TypeError, msg);
});
});
});
});