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))
Related
I am trying to automate the "UI testing" for my android application by using firebase testlab. I have saved a script in android studio but want to limit the robot for any further monkey testing. All it does is after my sctipts runs successfully, it starts doing monkey testing, which is of no use to me.
I read it online it can be controlled using "maxDepth" but couldn't find anything more. Would appreciate if someone could help me implement this.
maxDepth was only supported by Robo v1. It has been deprecated and has not had any effect on Robo tests for a long time. The standard way to limit the length of a Robo test now is to use the timeout flag/option.
A possible(?) alternative would be to have your Robo script exit your app when it is done, but I have never tried that and am not sure how it would work.
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?
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
I am trying to run the example code from the BigFlake Android samples, in specific this one example: CameraToMpegTest. I am new to Android development and I am not sure how I should treat this test suite. I try to create an Android Test Project in Eclipse but it doesn't run. Examples on the Internet seems to create an Android Test Project from a specific application project. Anybody tried to run these code and can give me some hint?
The bigflake samples were written as CTS tests, to be executed in the test harness (though some of them never actually turned into tests). If you're not set up with a full source tree it can be difficult to get them to work unmodified.
For a complete app example, see Grafika. The examples are a bit more involved, but you can get the code running more easily. In particular, "Continuous capture" and "Show + capture camera" will be of interest.
I have been using robotium to test my android application.Testing was successful but i want to know that is there any way to view test results in a separate file.
I have had good luck just running the robotium tests as regular Android JUnit tests, and then using the standard mechanism to get back the test results, namely the ant task fetch-test-report. To do this I used the build.xml file create by android through the tooling. See documentation for developing in other IDEs for detailed instructions on setting that up. Good luck!
XML report generation is quite simple when we are using Eclipse IDE
Steps to be followed
Run the Junit test as usual in eclipse Run As->Android Junit Test.
Once the test run is completed you will be indicated with the status in the status bar provided by the IDE.
When you click on the Test Run History Icon which is available in the Junit view of eclipse IDE you will find the Export option through which you can you can export the XML format test.
If you have and problems in finding the icon please watch the below image.
I use approach with logcat and android class Log.'severity'(tag, msg) ('severity' can be i-info, d-debug, w-warn, e-error, v-verbose), here is an example of clicking button myView:
String viewName = solo.getString(R.string.myViewName);
try {
solo.clickOnView((View) solo.getView(R.id.myView));
Log.i("Passed", viewName + " works correctly.");
} catch (Exception e) {
Log.e("Error", viewName + " doesn't work.");
}
Using filters you can filter output by tags and selecting all lines save it in .txt file. All these you can do automatically by writing simple script which will redirect output to file from InstrumentationTestRunner for you.
see also pages: Log class, logcat
In my case, I user spoon to generate test html reports. https://github.com/square/spoon
You can follow the way of your choice because it is not pure junit code:
1-XML based test execution report using any xml writing/parsing apis
2-logcat based test execution report using logs for example if you are using Eclipse IDE
3-customized report writing to your device under test, for this you will need apis to write to device
These are three ways out of several available as per your requirements and IDE.
You can use the PolideainstrumentationtestRunner, it allows you to specify exactly where you want to store the test result. (add option junitXmlOutput true and junitOutputDirectory yourPath)
http://code.google.com/p/the-missing-android-xml-junit-test-runner/
I hope it will help.