How to call Enter key press event in mobile app?

I want find a key word of Mobile Keyword to execute event “enter key press” on Android application?

1 Like

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)

2 Likes

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

1 Like

try to:
Mobile.setText(findTestObject(’’), ‘content\n’, 10)

“\n” will trigger the Enter

1 Like

I’ve tried with ‘\n’
But it doesn’t work at all

Can you help us for this issues?

Thank you

1 Like

Take a look at your code? @khadapynurhuda

1 Like

Yeah sure @roy.zheng

1 Like

sorry ,you can try “\\n” @khadapynurhuda
Is changed by the browser, missing a \

2 Likes

Hi @roy.zheng,

It has successful, but still can’t trigger the enter

1 Like

This is weird. Does it just type “Nasi Cap Cay” in the text but not trigger Enter?

1 Like

Yes, only that text.

And I add \n after it

May I know your script regarding this cases?

1 Like
Mobile.setText(findTestObject('android_V1/PickTask/Page_Pick/EditText_SCAN ILPSN'), LP_E + '\\n', timeout)

That’s what I did

1 Like

Why do you text LP_E as string but without quotes ’ '?

should it be without quotes?

1 Like

No, that’s my variable
I have an assignment in front
LP_E = ‘AAAA’

1 Like

Yeah, I can’t still trigger enter anyway

But thank you sir

1 Like

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.

1 Like

This worked for me.
Mobile.sendKeys(findTestObject(‘’), ‘\n’)

Thanks alot!

1 Like

This is weird. Does it just type “Nasi Cap Cay” in the text but not trigger Enter?

28 Likes