I want find a key word of Mobile Keyword to execute event “enter key press” on Android application?
Hi there,
In which case that you want to “enter key press”?
Set text in application’s field => We do provide “Set Text” keyword to handle this case
Send real key’s input such as “Right”, “Up”, “Left” , “Down”… => We didn’t have built-in keyword for this, but we will consider to add this later. In the meanwhile, our custom keyword capabilites can help you resolve this. Below is a sample custom keyword and how to use it in your test script:
Custom keyword:
package com.example
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import io.appium.java_client.AppiumDriver
import io.appium.java_client.android.AndroidDriver
import com.kms.katalon.core.annotation.Keyword
import com.kms.katalon.core.logging.KeywordLogger
import com.kms.katalon.core.mobile.keyword.MobileDriverFactory
public class MobileCustomKeywords {
static KeywordLogger logger = KeywordLogger.getInstance();
/**
* Press key on android's device.
* @param androidKeyCode Android's Key mapped into specific code: https://developer.android.com/reference/android/view/KeyEvent.html
*/
@Keyword
def pressKey(int androidKeyCode)
{
try{
AppiumDriver driver = MobileDriverFactory.getDriver()
AndroidDriver androidDriver = (AndroidDriver) driver;
androidDriver.pressKeyCode(androidKeyCode);
logger.logInfo("Press " + androidKeyCode )
}
catch (Exception ex){
println (ex.toString())
}
}
}
Use it in test script:
.....
import io.appium.java_client.android.AndroidKeyCode
CustomKeywords.'com.example.MobileCustomKeywords.pressKey'(AndroidKeyCode.ENTER)
The Keyword has an error on
import com.kms.katalon.core.mobile.keyword.MobileDriverFactory
It works fine after I changed it to
import com.kms.katalon.core.mobile.keyword.**internal.**MobileDriverFactory
try to:
Mobile.setText(findTestObject(’’), ‘content\n’, 10)
“\n” will trigger the Enter
I’ve tried with ‘\n’
But it doesn’t work at all
Can you help us for this issues?
Thank you
This is weird. Does it just type “Nasi Cap Cay” in the text but not trigger Enter?
Yes, only that text.
And I add \n after it
May I know your script regarding this cases?
Mobile.setText(findTestObject('android_V1/PickTask/Page_Pick/EditText_SCAN ILPSN'), LP_E + '\\n', timeout)
That’s what I did
Why do you text LP_E as string but without quotes ’ '?
should it be without quotes?
No, that’s my variable
I have an assignment in front
LP_E = ‘AAAA’
Yeah, I can’t still trigger enter anyway
But thank you sir
I had the same problem with you today.
I solved this by clicking on the input box and then entering the value +’\n’ to trigger Enter.
Hope this helps.
This worked for me.
Mobile.sendKeys(findTestObject(‘’), ‘\n’)
Thanks alot!
This is weird. Does it just type “Nasi Cap Cay” in the text but not trigger Enter?