Use Android Ui automator 2.0,How to get ActivityName? - android

I am using Uiautomator 2.0, which supports UiDevice.getCurrentActivity() to get currentActivity Name. However the results is not what I expect, instead it gets the App's Name.
What do I use to get the name of the current activity?

Seems like getCurrentActivityName() method is deprecated. developer.android.com/reference/android/support/test/… says "The results returned should be considered unreliable."
Though one of the ways to get the name list of activities of your application is using command prompt :
adb shell dumpsys activity | grep <package>
which could provide you with the list of activities active on your package.
* Recent #0: TaskRecord...
statement further includes the activities you have triggered using INTENT in your application and
mFocusedActivity:...
statement would specify the currently focussed activity of your application.

Related

I can't get the activity name using adb shell

I know that many people already sent questions similar to this. However, this is a little different.
I have to try to get the current activity from an android app, but it is not possible. Normally, I interact with the app and execute this: adb shell dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'. However, it always shows MainActivity. I checked the activity list on APK Info and this list is so little
So, there is some way to start a specific screen of apps similar to this?

How to record the activity name via AndroidViewClient/Culebra

In order to shorcut and go directly to the current activity page of Android I must first find the activity name, if it is a fragment I try to get the closest activity as possible. I use a few commands to find this info, like "adb shell dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'" or "adb shell dumpsys activity top". Unfortunately it seems that "adb shell uiautomator dump" has only the package name of the current activity in the xml file, so it is not useful. Is that possible for Culebra to record the activity name of the current activity and generate it's associated code when it is an activity and not a fragment, something like device.startActivity(component='...') ? This would be very helpful and will permit the play back of the generated script directly from the activity.
I think your idea may be very helpful to others so I decided to add this functionality to culebra v 10.3.4.
The context menu, now includes Generates a startActivity()
which generates a line like this in the output script (considering that in this example Calculator was the Activity on top of the stack)
device.startActivity('com.android.calculator2/.Calculator')

Detecting the Android keyboard with Calabash?

I am writing a series of automated tests for an android app using calabash-android and I need to be able to detect whether the android system keyboard is visible or not and (if possible) read some of the keys (i.e. if the return key says Done instead of Next or Enter). I know there is the keyboard_visible? commands for iOS but I have not been able to find anything similar for android.
Has anyone built their own functions to handle these instances?
there is a way to take a dump of the screens current contents on android using a tool called uiautomator from the android SDK. You can then check this for whatever you need to. It's not the most elegant solution but it might just work. Have a look at this post.
Calabash handling "Complete action using" dialog
windown_input_method = %x(adb -s #{ENV['ADB_DEVICE_ARG']} shell dumpsys window InputMethod | grep "mHasSurface")
windown_input_method.include?("isReadyForDisplay()=true")
This one returns true if keyboard is visible and false if not
ENV['ADB_DEVICE_ARG'] is environmental variable holding the device id of your android device connected. If you always run on one device, simply
windown_input_method = %x(adb shell dumpsys window InputMethod | grep "mHasSurface")
windown_input_method.include?("isReadyForDisplay()=true")
will do

Using adb to launch apps - using file as input and lacking activity name?

I would like to be able to launch specific apps over adb, reading them from a file.
For example - say I wish to launch 'com.ebay.mobile'. I have a file that has simply 'com.ebay.mobile' as the contents, and I'd then like to use a batch file to launch the contents of that file, for instance filling the rest of the command.
Obviously, this runs into difficulty with the lack of an activity name, so additionally, would it also be possible for the app to launch without specifying this, so the default activity launches?
Thanks for your help!
You can use the following 2 commands (you need to use both) to run an app - if you don't specify an Activity, it will use the Main one defined in the AndroidManifest file.
adb install yourAPKFile.apk
adn run com.your.package

How to launch an Android SubSettings Fragment?

For example, how do I launch User Settings? It's not implemented as its own Activity, so I'm not sure how to start it.
Below are some other similar questions but these are either more general or more specific. My question is about starting an arbitrary SubSettings fragment.
How do I call a specific PreferenceFragment from a PreferenceActivity?
Show only wireless system settings on Android 3
You can launch most Android Settings sub-screens by starting the SubSettings Activity and including the :android:show_fragment extra with the appropriate fully-qualified class name of an existing Android PreferenceFragment subclass.
For example, to start UserSettings:
adb shell am start -n com.android.settings/com.android.settings.SubSettings -e :android:show_fragment com.android.settings.users.UserSettings
To start DeviceInfoSettings:
adb shell am start -n com.android.settings/com.android.settings.SubSettings -e :android:show_fragment com.android.settings.DeviceInfoSettings
These examples use 'adb shell am start', but in principle you could invoke these in Java code (EDIT: Unfortunately you need to be signed with the system key, otherwise you get a SecurityException). Notice that the key for this extra has a colon at the front of it. To find other Settings, checkout the Android source and look for subclasses of PreferenceFragment in the packages/apps/Settings.
The situation was different in Froyo and before. In those days Activities were used to implement Settings sub-screens, so one could launch directly into a sub-screen (for example SoundAndDisplaySettings) by the usual method of calling startActivity() with a ComponentName or action String. This mechanism still works for some Settings sub-screens. For example, to bring up a wifi picker, you can use
adb shell am start -a android.net.wifi.PICK_WIFI_NETWORK
for MM :
am start -n com.android.settings/com.android.settings.SubSettings -e :settings:show_fragment com.android.settings.applications.RunningServices

Categories

Resources