Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Enter "Enter key" in Appium Testing

How to send/press Enter key from soft keyboard in Appium in Android Automation testing?
I tried several options, but none of them are working - instead of pressing the key, they are clearing the text entered in text area. Below is the code (in JAVA Language):

String app_package_name = "abc.xyz.android";

DesiredCapabilities capabilities = new DesiredCapabilities();
capabilities.setCapability("platformName", "Android");
capabilities.setCapability("deviceName", "Nexus_5X_API_23");
capabilities.setCapability("platformVersion", "6.0");
capabilities.setCapability("appPackage", app_package_name);
capabilities.setCapability("appActivity", app_package_name + ".activity.StartupActivity_");

String url = "http://127.0.0.1:4723/wd/hub";
AndroidDriver driver = new AndroidDriver(new URL(url), capabilities);
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);

By password = By.id(app_package_name_with_id + "et_password");
WebElement enterPassword = driver.findElement(password);
enterPassword.click();
driver.getKeyboard().sendKeys("12345");

driver.getKeyboard().sendKeys(Keys.ENTER); // THIS IS NOT WORKING.
driver.getKeyboard().sendKeys(Keys.RETURN); // THIS IS ALSO NOT WORKING.
driver.pressKeyCode(AndroidKeyCode.ENTER); // THIS IS ALSO NOT WORKING.
driver.pressKeyCode(AndroidKeyCode.KEYCODE_NUMPAD_ENTER); // SAME HERE.
enterPassword.sendKeys(Keys.ENTER); // SAME HERE.

Please if anyone can help me achieve it?

like image 641
pratik03 Avatar asked Aug 08 '17 14:08

pratik03


2 Answers

Before using

((AndroidDriver)driver).pressKeyCode(AndroidKeyCode.ENTER);

Set the following desired capabilities

capabilities.setCapability("unicodeKeyboard", "true");                                     
capabilities.setCapability("resetKeyboard", "true");
like image 66
anonyMouse Avatar answered Sep 20 '22 14:09

anonyMouse


you can try this, it will work with all devices

driver.executeScript("mobile:performEditorAction", ImmutableMap.of("action", "done"));
like image 25
Akash Avatar answered Sep 22 '22 14:09

Akash