Lets assume that I have a pretty big Android app and run test build on device (emulator or real) and go to some specific screen.
Is there any way to determine which screen is currently displayed on device? I.e. I'm on MainActivity screen with activity_main.xml layout and I want to find there this info is displayed.
I couldn't find such thing in Logcat.
Try to keep a unique tag name with the class Name as given below
private static final String TAG = "UniqueName" + EachCalss.class.getSimpleName();
while debugging time search with uniqueName
I found an answer in a pretty unexpected place.
You can track your displayed screens via Chrome.
Go to
chrome://inspect/#devices -> inspect your device -> elements.
There you can find your layout elements, activities, fragments etc.
Related
In the old logcat all I would have to do is type my package name in the search bar.
e.g com.dave.mynewapp
but now when you type in the package name it constantly displays log messages EVERY SINGLE SECOND that I don't need making it hard to debug.
Also now, the cursor doesn't automatically scroll down when a new log appears making it even more frustrating
I am able to filter it by typing the activity name... e.g MainActivity, but it becomes very annoying to type out every single class name that I have logs in.
Is there a way to get all the logs I manually created, but ignore the clutter I have in the picture above?
maybe you can try this :
filter specify the package name package:com.dave.mynewapp
filter specify the Tag tag:MainActivity
filter mutil tags like package:com.dave.mynewapp tag:MainActivity tag:MainActivity2
detail info about this link https://developer.android.com/studio/debug/logcat
I had luck by filtering on: tag:info
var tag = "info"
Log.i(tag, "Names: $names")
I am new for automation testing.
I am trying to automate UI and want to tap on humburger menu.
I tried it with
1. MobileElement el1 = driver.findElement(By.xpath("//*[#content-desc='" + "Menu" + "']"));
el1.click();
2. MobileElement el1 = driver.findElement(By.name("Menu)"));
el1.click();
3. MobileElement el1 = (MobileElement) driver.findElementByXPath("//android.widget.ImageButton[#content-desc=\"Menu\"]");
in all the cases i got error for element not found.
But when i tap manually on menu within test befor el1.click() get executed then test get run successfully. It is just like menu element get focused and appium find it.
So how to execute this without tap or getting focus?
Try to find the element by its name. In UI Inspector search before with name or any other locator. If it searches successfully with few attempts. Sometimes element has dynamic identification.
Can you try your code again but this time set the capability automationName to uiautomator2? Your problem sounds like the ones I have sometimes and moving from UIA1 to UIA2 (uiautomator2) solved that. UIA2 is however a bit more slow detecting elements IMO.
Background
Starting from Android O, it's possible to create pinned shortcuts, which (on supported launchers) show a dialog to confirm the creation of them:
ShortcutInfoCompat pinShortcutInfo = new ShortcutInfoCompat.Builder(context, uniqueShortcutId)
.setShortLabel(label)
.setIntent(shortcutIntent)
.setLongLabel(label)
.setIcon(IconCompat.createWithBitmap(bitmap))
.build();
ShortcutManagerCompat.requestPinShortcut(this, pinShortcutInfo , null);
Docs:
https://developer.android.com/reference/android/content/pm/ShortcutManager.html
https://developer.android.com/guide/topics/ui/shortcuts.html
The problem
Sometimes, the pinned shortcut is not relevant anymore. For example, it points to something that doesn't exist anymore.
In this case, I want to be able to remove it.
What I've tried
I thought this is possible by the next code, but it doesn't, because it is probably about dynamic shortcuts, which is something else :
ShortcutManager shortcutManager = (ShortcutManager) getSystemService(SHORTCUT_SERVICE);
final List<ShortcutInfo> pinnedShortcuts = shortcutManager.getPinnedShortcuts();
final ArrayList<String> shortcutIdsToRemove = new ArrayList<>();
for (ShortcutInfo pinnedShortcut : pinnedShortcuts) {
final Intent pinnedShortcutIntent = pinnedShortcut.getIntent();
shortcutIdsToRemove.add(pinnedShortcut.getId());
}
shortcutManager.removeDynamicShortcuts(shortcutIdsToRemove);
// this also doesn't work : shortcutManager.disableShortcuts(shortcutIdsToRemove);
The question
How can I remove pinned shortcuts? Is it even possible?
Update: seems it isn't possible, as Google mentioned here.
So far, this API seems very restricting to me, as it has so many disadvantages:
The created icon image cannot be created from a resource ID.
On the launcher, the created icon has a tiny icon of the app that created it.
The icon cannot be removed via the API (only disabled), so if you created one that points to another app, and this app was removed, you won't be able to remove it.
The creation cannot be in the background, as it requires a confirmation dialog. It also cannot be created in a batch. Only one after another.
All pinned shortcuts your app has created will be removed if your app was removed.
So, my question now is:
Is there any way to create and remove a shortcut using the previous API, using an adb command, with root if needed ?
Is it possible to remove specific pinned shortcuts using adb command , with root if needed?
disableShortcuts() is the best you can do. It will show the user a custom error message when they try to select the disabled shortcut.
From the official documentation:
Shortcut limitations
Although you can publish up to five shortcuts (static and dynamic shortcuts combined) at a time for your app, most launchers can only display four.
However, there is no limit to the number of pinned shortcuts to your app that users can create. Even though your app cannot remove pinned shortcuts, it can still disable them.
Another section:
Because your app and its users can pin shortcuts to the device's launcher, it's possible that these pinned shortcuts could direct users to actions within your app that are out of date or no longer exist. To manage this situation, you can disable the shortcuts that you don't want users to select by calling disableShortcuts(), which removes the specified shortcuts from the static and dynamic shortcuts list and disables any pinned copies of these shortcuts. You can also use an overloaded version of this method, which accepts a CharSequence as a custom error message. That error message then appears when users attempt to launch any disabled shortcut.
Note: If you remove some of your app's static shortcuts when you update your app, the system disables these shortcuts automatically.
I would like to write some UI Test on my Android application in order to take automated screenshots.
My application is written with React-Native.
In order to write my tests in need to know the resource-id of my component but as you can see in this screenshot i can't see any resource-id with ui Automator Viewer in this React-Native example app.
Look this picture.
I would like to know if there is a way to give some IDs to my components so I can write some test or if there is another way to select my components.
Note : I'm trying to write Espresso Test.
The testID only works on iOS, and is not mapped to the resource-id in Android.
You can specify an accessibilityLabel to your component. In uiautomatorviewer it shows up as content-desc
To be cross-platform, you should specify both:
<Text style={styles.welcome} accessibilityLabel="MyId" testID="MyId">
Welcome!
</Text>
You can then search for it using something like webdriver with the tilde selector browser.waitForExist("~MyId")
First of all, ID of each UI Component of Android objects has to be defined in the resource(res) folder as layout XMLs(you need to make sure you have defined it in the right tags) and to obtain the IDs in the Android please follow the steps:
1. Launch Android Studio, Click on "Android Device Monitor" icon next to "SDK Manager"
2. Connect your device and launch the application
3. Select your device name from the list of devices on the left panel
4. Click on Dump "View Hierarchy for UI Automate"
5. Now you can hoover over any view on thde device dump and can see Resource-d in the node details in the right column.
Note: You can also take screenshots
1)First thing first if its your project you can go to the layout and add id to these component and then take screenshot using uiautomator viewer you will find your resource id
2) If option 1 is not possible(that's highly unlikely to happen) you can still test it as from your screenshot i can see only one edittext box so using uiauatomator you can test it on the basis of the class . Here below is the code:
private static UiDevice mDevice;
func(){
mDevice = UiDevice.getInstance(getInstrumentation());
UiObject xyz=new UiObject(new UiSelector().**getClass**(android.widget.EditText));
xyz.click();
xyz.setText("abcdef");
}
// I am not sure its getclass() or getclassName() check both option
//xyz.click() is necessary as in uiautoamtor you won't be able to right text
in a textbox until and unless it is selected
Yes there is! You can pass a testID prop to any component that implements the <View /> props, as documented here.
testID string
Used to locate this view in end-to-end tests.
See also this very informative blogpost about UITesting in React Native. It is about iOS testing, but the javascript part is going to be the same for Android.
Sometimes when I'm working with my android projects, and hook up my phone, the logcat in Eclipse starts to report EVERYTHING that's happening on my phone, not just the stuff relative to the project I'm working on. It only does this sometimes though.
How do I stop it from showing everything and just show the things relative to my project?
EDIT:
I forgot to say i already know about filters, sorry. I was just wondering why sometimes eclipses logcat shows everything my phone is doing, while other times it only shows what's relative to the project i'm currently working with when running it on the phone.
I forgot to say i already know about filters, sorry.
Then it is because you have a filter selected and/or eclipse has encountered an error and is just not showing everything it should be.
First Answer
Next to your logcat window should be a Filter window. Create a filter there. Then select the filter by clicking the filter you have made or was put there automatically by eclipse.
You can filter on several things.
Most people will create a static string in their Main Activity/Service containing the application name. Use this static string as your TAG for all of your Logs. Then you can filter on this string you put for the static string.
Also, right clicking in the logcat window will bring up a filter dialog.
You can click on the session filter (left)
Use
Log.d("key","value");
Log.d("key1","value");
Log.d("key2","value");
Log.d("key2","value");
If you want to see only key1 messages ,then go to Logcat
click on add new logcat filter at top left corner(green color + symbol)
then a dialog box will be shown
then a dialog box will be shown, in that write Filter Name ie anyname
and in , by Log Tag write key1 and click on ok button.Now you will see a new filter on left side of your logcat
click on that,you will get only key1 messages
I could fix this by selecting my app in the DDMS-view.
It is important to select the app and not only the device. Latter will only create this useless "(Session-Filter)"
And this happens "sometimes" quite like the author asked for, i think if you change your mobile phone or just disconnect it.
http://developer.android.com/tools/debugging/ddms.html#logcat
You can also setup your own custom filter to specify more details such as filtering messages with the log tags or with the process id that generated the log message. The add filter, edit filter, and delete filter buttons let you manage your custom filters.
Use filters to define what you want to look at.
If you are using Eclipse, when viewing the LogCat view, there is a little green "+" button in the upper right corner. This will allow you to create a filter. Simply give your filter a name and input the TAG it should filter by.
If you are developing with Eclipse creating a log filter is what you are looking for.
If you are using logcat through adb from the command line: Filter LogCat to get only the messages from My Application in Android?