Can anybody tell me how can i use the keyboard keys while automating the mobile apps? I want to press the go button in mobile keyboard while making the script.
Which device OS (Android/ iOS) you are using? Different OS will have different ways to handle keyboard
Currently i am doing testing on android device.
Can anybody tell me how can i use the keyboard keys while automating the mobile apps?
Need help on urgent basis
Tester said:
Can anybody tell me how can i use the keyboard keys while automating the mobile apps?
Need help on urgent basis
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.
hi,
use Mobile.tapAtPosition(1075, 1900, FailureHandling.OPTIONAL)
try it.
Hi, I am unable to enter anything from soft keyboard in device through automation. I need to enter 4 digit pin by selecting each digit from the device soft keyboard. Can you please let me know how to automate it?
Also, the above code throws error when test case is run.
You can try using âadbâ command. Refer here: https://www.raizlabs.com/dev/2017/09/automating-input-events-android/. Basically this adb command can be called directly from either cmd (Windows) or terminal(macOS) and so in your script just create a util served as wrapper to call the command, e.g: http://blogs.sheelapps.com/2013/03/run-system-command-in-groovy.html
I updated the response above to include the import
statements youâll need in order to use the keyboard. The AndroidKeyCode
class should have all the keys you need to interact with the pin screen: AndroidKeyCode.KEYCODE_0
through AndroidKeyCode.KEYCODE_9
.
If youâre still receiving errors, could you please provide a log and screenshot of the error.
Thanks,
Chris
Hi Chris,
Am not getting any errors. The TC is passed but nothing happens. It is not clicking on the numbers. Actually this keyboard is present on the screen by default once we navigate to this screen. Once we tap on numbers, the circle gets highlighted in black. Not sure if this is behaving as a soft keyboard.
You might have better luck by disabling the soft keyboard in Android. Youâd do this by setting the unicodeKeyboard
and resetKeyboard
capabilities to true
. You can do this right before starting the app in your test:
import com.kms.katalon.core.configuration.RunConfiguration
RunConfiguration.setMobileDriverPreferencesProperty("unicodeKeyboard", true)
RunConfiguration.setMobileDriverPreferencesProperty("resetKeyboard", true)
Hope this helps,
Chris
Hi Chris,
Its me again, so Iâm trying to enter numeric digit using the android keypad as well and I able to enter the digits just fine but I need to press the âDONEâ button within the android keyboard which will lead to me the next screen. so far I have included these codes and here are my errors and the actual screen shot of the application, please help me resolve this issue.
BTW I have already imported- import io.appium.java_client.android.AndroidKeyCode
Hi @rkarim,
The error youâre seeing is similar to the error you saw before with startX
and startY
: you are repeating the:
AndroidDriver<?> driver = MobileDriverFactory.getDriver()
line, which is unnecessary. That line sets up the driver
variable, and once itâs done one time in your test, you donât need to do it again, you can just use:
driver.pressKeyCode(AndroidKeyCode.ENTER)
.
â Chris
Hi Chris,
I tried commenting out that line and running the âdriver.pressKeyCode(AndroidKeyCode.ENTER)â code and it doesnât press the enter button within the numeric android keyboard, Actually there isnât any enter button within the keyboard its called DONE button, can you please help?
Hi @rkarim,
I wonder if AndroidKeyCode.KEYCODE_NUMPAD_ENTER
would work in this case since itâs more specifically for a number pad.
â Chris
Hi @Chris_Trevarthen,
Unfortunately AndroidKeyCode.KEYCODE_NUMPAD_ENTER code didnât work, it executes successfully but doesnât tap on the Done button within the keyboard at all.
Hi @rkarim,
Thatâs unfortunate that the keys arenât working for you. Have you been able to use the Spy Mobile tool and try to capture the object for that key? That might give some hint as to what type of element it is.
The alternative, if we canât get the key to work, is to use Mobile.tapAtPosition
to just tap the screen at a certain coordinate that you know will be within the Done button:
https://docs.katalon.com/katalon-studio/docs/mobile-tap-at-position.html
Hope this helps,
Chris
Hi Chris,
If the the âDoneâ button of the keyboard is at the very bottom right corner of the screen how can I predict the x and y coordination for this button. Iâm asking you this is because my native keyboard can not be recognized by the katalon studio spy, thatâs why Iâm trying to TapAtPosition method.