Weekly Katalon FAQs (14) - Mobile Testing (How to handle keyboard on Mobile device)

:pushpin: FAQs under this topic:
45. How to press the Next/Return/Enter button on the Android keyboard
46. Press and hold button not affect on Katalon
47. How to use the keyboard keys while automating the android app


:point_right: See also Weekly Katalon FAQs

45. How to press the Next/Return/Enter button on the Android keyboard

45.1 Scenario:

The user would like to press the Next/Return/Enter button on the Android keyboard:

45.2 Solution:

Currently, Katalon Studio hasn’t supported performing the actions on a physical keyboard directly yet. However, we have some suggestions here so you can try it out:

1. Use AndroidKey library

This library will help to press the Enter button and here’s my sample script for this use case:

import io.appium.java_client.android.AndroidDriver
import io.appium.java_client.android.nativekey.AndroidKey
import io.appium.java_client.android.nativekey.KeyEvent
import com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactory as MobileDriverFactory

Mobile.startApplication('/Users/vi.kim/Desktop/Desktop/Mobile App/MB Bank_5.7_apkcombo.com.apk', true)

Mobile.delay(20)

Mobile.tap(findTestObject('Object Repository/android.widget.EditText - Tn ng nhp'), 0)

Mobile.setText(findTestObject('Object Repository/android.widget.EditText - Tn ng nhp (1)'), '12345', 0)

AndroidDriver<?> driver = MobileDriverFactory.getDriver()

driver.pressKey(new KeyEvent(AndroidKey.ENTER))

The behavior here is that after performing the setText step, I press Enter key and it’s able to be pressed. Since my sample app is a bit different from yours, the keyboard is just hidden after pressing the Enter key.

:point_right: Please find this video for more details.

2. Use Mobile.tapAtPosition

This keyword helps you to tap at a specific position on the screen of the mobile device. Here’s how I can get the position of the Enter button:

  • Use the Mobile Spy Recorder tool and start the application
  • The Enter button has a similar position to the “Chat” object

  • Then select the “Chat” object to get the value of its position: x, y

  • Use that value in my below sample script:
Mobile.startApplication('/Users/vi.kim/Desktop/Desktop/Mobile App/MB Bank_5.7_apkcombo.com.apk', true)
Mobile.delay(20)
Mobile.tap(findTestObject('Object Repository/android.widget.EditText - Tn ng nhp'), 0)
Mobile.setText(findTestObject('Object Repository/android.widget.EditText - Tn ng nhp (1)'), '12345', 0)
Mobile.tapAtPosition(859,1610)
  • And the expected result is that the Enter button can be pressed in that position.

:point_right: Please find this video for more details.

46. Press and hold button not affect on Katalon

46.1 Scenario:

The user needs to tap on an object 3 times and hold it for the fourth Time to open another screen.

  • For Android: It’s working as expected
  • For iOS: it’s not working

Expected Result:

After taping 3 times and holding for the fourth time it should open another screen.

Actual Result:

All the steps are showing as passed but on the iOS device, action is not performed it is not navigating to another screen.

46.2 Solution:

Add the below library and use the mobile element.click as below:

import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.mobile.helper.MobileElementCommonHelper
import io.appium.java_client.MobileElement

MobileElement element = MobileElementCommonHelper.findElement(findTestObject('element id'), 10)
element.click()

47. How to use the keyboard keys while automating the android app

On Android, you can interact with the keyboard through:

Import the following at the top of your test:

import com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactory

import io.appium.java_client.android.AndroidDriver
import io.appium.java_client.android.AndroidKeyCode

And then use this code to access the keys:

AndroidDriver<?> driver = MobileDriverFactory.getDriver()
driver.pressKeyCode(AndroidKeyCode.ENTER)

Where AndroidKeyCode is an enum with all of the possible key entries, e.g. KEYCODE_0, KEYCODE_A, etc.

:point_right: See the list of Android Key here.

Video Detail of Test Run

You can watch the video of the Test Run for more detail.

3 Likes

Great insight and feedback !