Detect or Suppress Keyboard in UiAutomator Tests - android

In my UI tests I am setting the text of two UiObjects near the top of the screen, and clicking on third UiObject which is located near the bottom of the screen. On some devices (eg my Nexus 6 running 5.0) this works perfectly. The text is set, the UiObject at the bottom of the screen is still visible, and it is successfully clicked on.
On other devices (eg my Nexus 4 running 4.4) calling setText on the UiObjects brings up the soft keyboard, which obscures the third UiObject near the bottom of the screen and prevents it from being clicked on.
I considered using UiDevice.pressBack() to dismiss the keyboard, but the problem is that the keyboard shows on some devices and not others. Pressing back on the devices that do not show the keyboard causes other behavior which leads to the test failing.
I also considered using UiDevice.pressEnter() as a solution. I figured this would dismiss the keyboard if it was visible, and do nothing if it wasn't (best of both worlds). The problem is, that the keyboard shown by UiAutomator when it is running my tests does not have an "enter" button, it has a "next" button. This is contrary to the way I have the actual UI elements setup in code though. When I test this manually the keyboard shows the "enter" button as expected. However, since UiAutomator is seeing the "next" button, that is the functionality it is executing. The focus simply passes to the next UiObject and the keyboard is still visible.
So what I am trying to do is dismiss the keyboard IF it is visible, without risking pressing the back button if it is not. Is there a way to determine if it is showing or not? Or better yet, never show it in the first place?

Different device have different packages, and keyboards function may different too.
So, the details may not be all the same.
Steps listed below are succeed in Android 4.0+ on my device:
Disable packages relative to keyboard input method.
The commands are listed here:
adb root
adb shell pm disable com.google.android.apps.inputmethod.hindi
adb shell pm disable com.google.android.inputmethod.korean
adb shell pm disable com.google.android.inputmethod.pinyin
adb shell pm disable com.google.android.inputmethod.latin
adb shell pm disable jp.co.omronsoft.iwnnime.ml
pause
Note: Some package name like "com.google.android.inputmethod.pinyin" may not exist in device.
Use this command to check:
adb shell pm list packages inputmethod
Disable the "Google voice typing"
"Google voice typing" can still popup the keyboard.
If you want to disable keyboard:
Go to Settings → Apps → Running (or All) → "Google Keyboard" → Settings → Disable "Google voice typing".
Note: If you want enable the keyboard, run command like this:
adb shell pm enable com.google.android.inputmethod.latin

I guess I found a way to make the tests pass, which is to simply scroll the screen down further. In my case the UI is scroll-able, so this works.
UiScrollable layout = new UiScrollable(new UiSelector().resourceId(...));
layout.scrollForward(5);
I am posting this in case it helps anyone in a similar situation. It does not actually answer my question though, so I am not accepting this.

I think maybe you can try this : Write a if() on that step , if cannot find the UiObject in that view ,then UiDevice.pressBack().

Related

Shortcut for "Commit and Push" option of Android Studio "Code Analysis dialog"

I try to reduce use of mouse and hence look for / set shortcut keys for common functions. This one has been challenging.
Often dialog like this (for android studio 4.2-, this comes as banner from top) when I try to commit. I know ideal would be to fix those warnings but what if I really want to ignore those warnings. I want to execute "Commit and Push" just by using keyboard. I tried with different key combinations (like cmd+option+c/i/p), tab key but focus remains on "Review". (AS 4.2- is even worst, I can change focus with tab but as soon as I hit "Enter" it just execute "Review).
I can use some experts' advice. How can I execute "Commit and Push" from this dialog only with keyboard?
This popup is a new macOS native alert.
To make to turn on the keyboard navigation in alerts, please, go to macOS System Preferences->Keyboard->Shortcuts and check the Use keyboard navigation to move focus between controls option. After enabling it, you will be able to navigate in alerts with Tab/Shift+Tab and once you are on "Commit and push" press Spacebar to confirm.

App with own soft keyboard by default

I'm creating a app and want him to have his own custom soft keyboard by default, but I don't know how do this.
So far I have the app and a separate app for the keyboard, I tried to set the custom keyboard by default but don't managed to do that, the only way I found for enable him is via shell and enabling manually in the phone configuration, the shell command that I use:
ime enable package/appName
ime set package/appName
I tried to execute this commands via:
Runtime.getRuntime().exec();
Tried to put in the init files too, tried to substitute the default android keyboard, but nothing works.
If anyone can help me you have my thanks.

How to disable showcase view in Android emulator

I'm using Android emulator in Jenkins to run functional tests (Cucumber). Everything works fine if the emulator doesn't contain showcase view at the start.
But if there is a showcase view my tests fail, because application runs behind this view.
I've tried to send keyevents using adb to the emulator before using it:
adb shell input keyevent KEYCODE_MENU;
but it doesn't help. I've tried KEYCODE_MENU, KEYCODE_BACK and other keys, but they don't disable this view.
I guess this property should be available as a system preference in the Android, but I can't find it :(
How can I disable showcase view in emulator? I have access to the emulator using adb.
UPDATE
There's no such flag which can be set in emulator config file or passed to emulator at the start.
And I still don't have a clean solution for this, but few workarounds exist. And that's understandable as showcase view is just a view from Launcher application and logic for that is inside Launcher application.
tricky way, but universal: Prepare custom Android Launcher application with disabled showcase (based on AOSP Launcher) and pre-install (replace default launcher) it on target emulator.
manual way, not universal: gather list of emulators used and coordinates of OK button on those, and send appropriate touch coordinates upon emulator start (as Christopher Orr proposed)
You should be able to send a tap event, for example:
adb shell input tap 700 900
That would tap at approximately the correct x,y pixel coordinate for that button on a Nexus 4.

I am keep getting message: Unfortunately "some chinese" has stopped

I am keep getting this each 10 sec. What is it about? How can I fix this?
This problem is not related to any app I created, it just happens on emulator I work on in eclipse. I thought it's some common 'error'. I may just lunch avd, unlock the screen and wait few sec for this message to comes up.
This is my very first contact with android emulator, so I am not that fluent, didn't know what else to post. I found logcat but it is empty.
These chinese characters say:"Google's PinYin input method",so I guess this problem is related to the input method(PinYin is a way to mark the pronunciation for a character with Latin letters) . It seems that this happens when you are inputting something in the TextView. On the emulator, there is a native Google PinYin input method and perhaps this app has something wrong. Please disable it or create a new emulator.
Actually, how is your app on a real device?
There is probably a Japanese keyboard trying to run, turn it off from Settings->Language & Keyboard
Being a couple of days into Android development, I encountered the same issue. It only began, however, after I was playing around with the system settings of the emulator. I could have sworn that I didn't change a thing in the languages and settings menu. But, since I did inspect it and this dialog did appear, I'm sure it did. My emulator has mucho latency due to the fact that my dev machine is a few years behind the times ( a good development practice btw.)
So, I did the following:
enable: system settings->Dev Settings and check Show cpu usage
this shows you all android processes running. You will see:
com.android.pinyin
just before the error.
google that error and hopefully come across this post.
go back into system settings->Language and input and change the default back to English.
I was having the same problem using the 4.0.3 WXGA800 emulator but could not disable the Chinese keyboard nor the Japanese IME keyboard since the check mark was greyed out (not blue). I was about to post a question when, by mistake, I clicked on the Default option, cycling through the different options until I came back to English (US). After that, fortunately the message stopped appearing.
I tried to post an image to show the check marks and the Default option, but as a new user was not able to.
I have the same problem as #Bobby, from Android +4 the check is unavailable. The solution was to disable the Chinese application. To make disable go to "Settings" > "Apps", tap on "ALL" option in the action bar tab on the top, and at the end of the list you will be found the application, then tap in the item, and in the next screen make click in "Force stop" button and "Disable" button.
This is my fix:
Settings > Language & Input > Keyboard and Input Methods > Default > English (US)
Changed default to another language and then back to English (US)
Message hasn't appeared for over 9000 seconds

Stop on screen keyboard appearing for Android Emulator?

I am using the AVD manager in eclipse. Is there a setting that I can use to stop the on screen keyboard appearing when an input field has focus?
I tried has hardware keyboard = true, but then the emulator doesn't seem to start at all :-S
mstoic's answer works, but with one problem: Google voice typing gets enabled with no way to get rid of it.
Not sure if this is available in emulators of all Android versions, but I found this in Settings -> System -> Languages & Input -> Physical keyboard (API 29 emulator). It worked for my use case.
The emulated device should have a physical keyboard, therefore negating the need for a soft keyboard.
I tried it out now and this configuration combination works for me:
hw.keyboard=yes
hw.touchScreen=no
The AVD has a physical keyboard, but no touchscreen, therefore only the physical keyboard can be used for text input, and the emulator does not show the soft keyboard.
Simply disable the Gboard app on your emulator.
To do that, go to Settings > Apps > Gboard, and then click the "DISABLE" button.
If Gboard is not visible, make sure you select the three dots in the top right corner and select the "Show system" option.
In some apps, you may see the Voice input box instead of the keyboard, you can disable that too by disabling the Google app in the same way you disabled Gboard.

Categories

Resources