Android P Preview breaks UiAutomator tests with API compatibility error - android

I am trying out Android P preview on Pixel device, and currently experiencing an issue with instrumentation tests written with UiAutomator framework.
Whenever a button click is simulated with UiAutomator by following code:
onView(withId(R.id.button_activity_login)).perform(click())
I am encountering an AlertDialog with message
Detected problems with API compatibility (visit g.co/dev/appcompat for more info)
which leads to this link:
https://developer.android.com/preview/restrictions-non-sdk-interfaces.html#differentiating_between_sdk_and_non-sdk_interfaces
This breaks UiAutomator tests since my tests currently do not consider additional AlertDialog between each action.
This only happens with UiAutomator's button click, not with Espresso's. I believe that UiAutomator might use some reflections under the hood in order to achieve cross-app testing functionality (not knowing the UI component's texts or ids beforehand), whereas Espresso takes care of everything inside the app being tested.
This is somewhat weird since UiAutomator is a testing framework Google itself suggests in their developer sites (https://developer.android.com/training/testing/ui-automator.html#ui-automator-apis). Does anybody have experienced or solved the following issue?

Related

Camera Automation Testing In Android

I am doing automation testing using Espresso but I struggle in Camera Capture... I have written code for camera that it will open, but it is not able to click. What I need is to click in automatically if it is possible.
Please give me any suggestions. Below is my code:
onView(withId(R.id.photo)).perform(click());
Things get tricky with Espresso when you are working with tests that include multiple Activities. I prefer to use UIAutomator for such parts of the test.
With UIAutomator, you can do something like:
UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
.findObject(new UiSelector()
.resourceId("com.example.package:id/photo")).click();
Remember that your IdlingResources won't have any effect on UIAutomator, so you might need to add extra delays to wait for that Activity to be created and initialized before it is clicked on.
Here is how to setup UIAutomator: UIAutomator Testing | Android Developers

Any remote debugger to inspect a running Android app layout?

I am looking for a way to inspect an running Android application layout (preferably, by dp/sp), like something as you can see in those Google Chrome/Firefox/Safari live HTML inspector feature.
I have an Android app which needs to follow a strict design guideline and comparing between the guideline and the application itself is quite cumbersome and taking a lot of time to jump around multiple source codes and layout .xml(s) to check a design conformity, so it'd be very efficient to have such debugger.
I should also mention that the app needs specific Android devices to run (unable to run on an simulator or unapproved devices).
Your ideas would be greatly appreciated.
Thank you.
You can test this built-in feature in android studio run the app and after click on the layout inspector "

Testing Google Android Places Autocomplete with Espresso

I'm struggling with instrumental ui test of a PlaceAutocomplete API, provided by Google.
What I'm trying to test is ability to open AutoComplete Activity (fired with proper button), enter some text, pick result from given list and check if picked position is listed on the recyclerview.
I'm trying to target this EditText below :(
with:
onView(withClassName(equalTo(EditText.class.getName())))
.inRoot(withDecorView(not(is(homeActivityActivityTestRule.getActivity().getWindow().getDecorView()))))
.perform(typeTextIntoFocusedView("kotek"), closeSoftKeyboard());
And other variations, like withText "Szukaj" or with com.google.android.gms.R.id :) without luck.
Help will be appreciated! Thank You!
This view is auto-generated by Google Api.
If it's true, sorry I haven't any experience with Places API, it would mean that Espresso is unable to find this view.
Solution: Espresso Test Recorder
You can install the latest Android Studio 2.2-RC2 (don't remove the previous) from: http://tools.android.com/download/studio/builds/2-2-rc to check brand new Espresso Test Recorder (check: http://tools.android.com/tech-docs/test-recorder) and try to get this view by click on this to generate code, but I said this might not help.
Solution: Espresso with uiatomator
My doubts about it come from Espresso framework limitation - it depends on actual context of app, it means that it may not recognize intents, genereated code or notifications.
Try to use typical instrumentation framework like Google's uiatomator. There's no problem to use it along with Espresso UI testing framework.
Read: http://qathread.blogspot.com/2015/05/espresso-uiautomator-perfect-tandem.html
More info you would find here: http://google.github.io/android-testing-support-%20/docs/uiautomator/
Solution: Espresso with Robotium or Robotium Test Recorder
If you find uiatomator a pretty hard to learn you can also use another instrumentation test framework called Robotium, which has clean and conchise syntax with some powerfull functions like taking screenshots.
It can work along with Espresso. Check last paragraph of this article: https://github.com/codepath/android_guides/wiki/UI-Testing-with-Robotium
It also has its own recorder: http://robotium.com/products/robotium-recorder. Try it for free, but I doubt that you would find it useful, as Robotium code is really simple to learn.
Hope it will help
Install Android studio 2.2 Beta, Try the Espresso test recorder. It will automatically generate an Espresso test case for you.
Try with this one :-
Espresso.onView(ViewMatchers.withId(R.id.places_autocomplete_edit_text))
.perform(ViewActions.typeText("<ADDRESS>"))
Thread.sleep(3000);
onView(withText("<ADDRESS FROM SUGESSION>"))
.inRoot(withDecorView(Matchers.not(activityTestRule.activity.window.decorView)))
.perform(click())
Tested with :- Android Studio:3.5.2 | espresso-core:3.1.1 | places:1.1.0
Autocompleater component seems to be not accessible using espresso, one solution is to send typing then clicking through a shell
getInstrumentation().getUiAutomation().executeShellCommand("input text n")
sleep(2000)
getInstrumentation().getUiAutomation().executeShellCommand("input tap " + Math.round(width / 2f) + " " + Math.round(height / 4f))

Android Usability Testing Setup (ddms, screenshots, touchevent)

im thinking of an easy-to-use android usability testing tool, that will allow the user to record and log relevant information during app testing. As a first result i would like to have a screenshot taken each time the user interacts with the touchscreens where the position, duration and type of the touch event is shown.
As android does not allow me to take screenshots easily and as its not possible to log touchevents from an service here are my questions:
Does Logcat give me any information about TouchEvents (I tried but i couldt produce any touch-Logs)
Is it possible to evoke the ddms-Screenshot-action from terminal? (./ddms -takescreenshot)
Does Logcat give me any information about TouchEvents (I tried but i couldt produce any touch-Logs)
No.
Is it possible to evoke the ddms-Screenshot-action from terminal? (./ddms -takescreenshot)
Not via the ddms command AFAIK. Either use monkeyrunner (as another answer suggested), or write your own code to the JAR file that DDMS uses. I used that to create a software projector; another developer extended that concept.
If you are looking to automate these things, you can use the Monkey Runner tool, it specifically has a call to take screen shots automatically.
http://developer.android.com/guide/developing/tools/monkeyrunner_concepts.html
It specifically runs Python scripts, that you would use to design an automated regression test.

Android - issue in controlling builtin app using Robotium

I am writing an android testing application which automates testing on the device.
I am targeting facebook as my base application and writing an app using the Robotium framework in order to accomplish my requirement.
Until now i have successfully implemented a few features, but I am stuck at one point: I want to automate the "upload picture" functionality, but as soon as the upload button is clicked, the device builtin application gets activated. I could not control the default app using Robotium.
Is there any way to solve this, by writing some code using robotium or writing a layer between the OS and Robotium which can generate key stokes?
I don't think you can do that. However you might be able to make your own modified version of the built-in application and use that instead (if you can make it default and so not have to go through a selection screen), or root a phone and break its security model to use as an automated testing device.
You said
a layer between the OS and Robotium.
If you were ok with that, there is the black-box UIAutomator-Framework by google, which might be able to do that.
Additionally,
You might want to use monkeyrunner like this:
$ monkeyrunner
>>> from com.android.monkeyrunner import MonkeyRunner, MonkeyDevice
>>> device = MonkeyRunner.waitForConnection()
>>> device.touch(200, 400, MonkeyDevice.DOWN_AND_UP)
You can also do a drag, start activies etc. Have a look at the api for
MonkeyDevice.
(from this SO answer).

Categories

Resources