AndroidKeyCode deprecated and problems using now AndroidKey

Problems with AndroidKeyCode deprecated (this code was working well few days ago)

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

Mobile.comment(‘PIN SETUP’)

//Tap the object to get the keyboard activated
Mobile.tap(findTestObject(‘PIN/Pin_1’), 0) //tap the object in order to activate the keyboard

AndroidDriver<?> driver = MobileDriverFactory.getDriver()
driver.pressKeyCode(AndroidKeyCode.ENTER)
driver.pressKeyCode(AndroidKeyCode.KEYCODE_1)
driver.pressKeyCode(AndroidKeyCode.KEYCODE_2)
driver.pressKeyCode(AndroidKeyCode.KEYCODE_3)
driver.pressKeyCode(AndroidKeyCode.KEYCODE_4)

I replaced by the method Androidkey and i still have problems
Can someone help me to implement the libraries
import io.appium.java_client.android.nativekey.keyEvent
import io.appium.java_client.android.nativekey.AndroidKey

What I tried to implement was:
import com.kms.katalon.core.mobile.keyword.internal.MobileDriverFactory as MobileDriverFactory
import io.appium.java_client.AppiumDriver as AppiumDriver
import io.appium.java_client.android.AndroidDriver as AndroidDriver
import io.appium.java_client.android.nativekey.keyEvent
import io.appium.java_client.android.nativekey.AndroidKey

Mobile.comment(‘PIN SETUP’)

//Tap the object to get the keyboard activated
Mobile.tap(findTestObject(‘PIN/Pin_1’), 0)

AndroidDriver<?> driver = MobileDriverFactory.getDriver()

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

driver.pressKey(new keyEvent(AndroidKey.DIGIT_1))

driver.pressKey(new keyEvent(AndroidKey.DIGIT_2))

driver.pressKey(new keyEvent(AndroidKey.DIGIT_3))

driver.pressKey(new keyEvent(AndroidKey.DIGIT_4))

and the error i had was “…Pin/Script1569454645784.groovy: 18: unable to resolve class io.appium.java_client.android.nativekey.keyEvent
@ line 18, column 1.
import io.appium.java_client.android.nativekey.keyEvent”
and still not working, please help

Please use import:

import io.appium.java_client.android.nativekey.KeyEvent

instead of

import io.appium.java_client.android.nativekey.keyEvent

Thanks @duyluong ,

works perfect in Bluestacks emulator :):grinning:
But in Android emulator doesnt write anything and marks the step as a PASS and doesnt continue further with the next screens :frowning:

Do you know why ?

Please refer to this if the enter key press doesn’t work:

1 Like

Thanks, the solution offered in the link you sent me it worked perfectly in Android Studio.

import io.appium.java_client.android.nativekey.KeyEventFlag as KeyEventFlag

driver.pressKey(new KeyEvent(AndroidKey.).withFlag(KeyEventFlag.SOFT_KEYBOARD).withFlag(KeyEventFlag.KEEP_TOUCH_MODE).withFlag(KeyEventFlag.EDITOR_ACTION))

:slight_smile:

1 Like