Skip to content

Instantly share code, notes, and snippets.

@0x1mason
Created September 17, 2014 13:08
Show Gist options
  • Save 0x1mason/4c551b285103bb57c5c6 to your computer and use it in GitHub Desktop.
Save 0x1mason/4c551b285103bb57c5c6 to your computer and use it in GitHub Desktop.
hide keyboard
it('should hide keyboard using bad key', function (done) {
driver
.elementByClassName('UIATextField').sendKeys("1")
.elementByClassName('UIASwitch').isDisplayed()
.should.become(false)
.hideKeyboard("f")
.elementByClassName('UIASwitch').isDisplayed()
.should.become(true)
.nodeify(done);
});
iOSController.hideKeyboard = function (strategy, key, cb) {
this.proxy("au.hideKeyboard(" +
"'" + strategy + "'" +
(key ? ",'" + key + "'" : "") +
")",
cb);
};
, _tryWaitKbHidden: function() {
var interval = 50, t = 0;
while(t < 3000 && !$.mainApp().keyboard().isNil()) {
t += interval;
$.delay(interval);
}
return $.mainApp().keyboard().isNil();
}
, _doHideKeyboard: function (keyName) {
// $.debug("Hiding keyboard with keyName " + keyName);
// var key = this.keyboard().buttons()[keyName];
// if (key.isValid()) {
// key.tap();
// } else {
// $.debug("Hiding keyboard using default method");
// var startY = $.mainApp().keyboard().rect().origin.y - 10;
// var endY = $.mainWindow().rect().size.height - 10;
// $.flickApp(0, startY, 0, endY);
// }
$.debug("Hiding keyboard using default method");
var startY = $.mainApp().keyboard().rect().origin.y - 10;
var endY = $.mainWindow().rect().size.height - 10;
$.flickApp(0, startY, 0, endY);
}
, _tapOutside: function () {
$($.mainWindow()).tap();
}
, hideKeyboard: function (strategy, keyName) {
if($.mainApp().keyboard().isNil()) {
return;
}
switch (strategy) {
case 'press':
case 'pressKey':
$._doHideKeyboard(keyName);
break;
case 'tapOut':
case 'tapOutside':
$._tapOutside();
break;
case 'default':
$._tapOutside();
break;
default:
throw new Error('Unknown strategy: ' + strategy);
}
if(!$._tryWaitKbHidden()) {
throw new Error("Failed to hide keyboard.");
};
}
@0x1mason
Copy link
Author

Results in {"status":17,"value":"Failed to hide keyboard."}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment