Keyboard Events
Hide Keyboard:
Create a reusable function and call when required in test script
public static void hideKeyboard() throws Exception {
try {
driver.hideKeyboard();
} catch (Exception e) {
throw new Exception("Keyboard should auto-trigger but didn't");
}
}To hide keyboard call above function from helper.java class
test.java
$ helper.hideKeyboard();Open Keyboard:
To create a reusable function and call in test script
// Android
public static void getKeyboard() throws Exception {
if (driver instanceof AndroidDriver) {
((AndroidDriver) driver).pressKeyCode(AndroidKeyCode.KEYCODE_PAGE_UP);
}
}To open keyboard call above function from helper.java reusable class
test.java
$ helper.getKeyboard();Press key Enter:
To create a reusable function and call in test script
// Android
public static void pressKeyEnter() {
if (driver instanceof AndroidDriver) {
((AndroidDriver) driver).pressKeyCode(AndroidKeyCode.ENTER);
}
}To press key ENTER call above function from helper.java reusable class
test.java
$ helper.pressKeyEnter();Press key UP:
To create a reusable function and call in test script
// Android
public static void pressKeyUp() {
if (driver instanceof AndroidDriver) {
((AndroidDriver) driver).pressKeyCode(AndroidKeyCode.ACTION_UP);
}
}
To press key ENTER call above function from helper.java reusable class
test.java
$ helper.pressKeyUp();Last updated
Was this helpful?