Created
September 17, 2014 13:08
-
-
Save 0x1mason/4c551b285103bb57c5c6 to your computer and use it in GitHub Desktop.
hide keyboard
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
iOSController.hideKeyboard = function (strategy, key, cb) { | |
this.proxy("au.hideKeyboard(" + | |
"'" + strategy + "'" + | |
(key ? ",'" + key + "'" : "") + | |
")", | |
cb); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
, _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."); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Results in
{"status":17,"value":"Failed to hide keyboard."}