java,android,ant,android-espresso
Using ant you can repack the jar excluding the LICENSE.txt file like this: <move file="libs/hamcrest-core.jar" tofile="libs/hamcrest-core-in.jar" /> <jar destfile="libs/hamcrest-core.jar"> <zipfileset src="libs/hamcrest-core-in.jar" excludes="LICENSE.txt"/> </jar> <delete file="libs/hamcrest-core-in.jar"/> Do this for all three files and the dex problem is gone....
android,unit-testing,junit,android-espresso,activityunittestcase
After banging my head against the wall, windows and various furniture, I finally got my tests working! From a response on its issue tracker, I learned that no new Handlers can be created from the instrumentation thread. Which means startActivity() must be invoked in the UI thread. Which leads to...
As Error shows Problem views are marked with '****MATCHES****', and if you follow error you find '****MATCHES***' in front of a ListView and a Spinner in hierarchy. In order to solve this problem where you have multiple adapter views, you can call ViewMatchers.inAdapterView(): onData(isFooter()).inAdapterView(withId(R.id.list)).perform(click()); And you are done....
This is a strange issue, so I will give a resolution that worked for me first and then try to explain what I think is happening. Quick fix is to redeclare your Support Library dependencies in test build configuration: androidTestCompile 'com.android.support:support-v4:22.1.1' androidTestCompile 'com.android.support:appcompat-v7:22.1.1' androidTestCompile 'com.android.support:cardview-v7:22.1.1' androidTestCompile 'com.android.support:gridlayout-v7:22.1.1' androidTestCompile 'com.android.support:recyclerview-v7:22.1.1' This...
android-testing,android-espresso
You can either do a lot of work and use an IdlingResource to implement an OnPageChangeListener or simply: SystemClock.sleep(500); ...
android,expandablelistview,android-espresso
There are several points of using adapter views. If it is loading data from adapter you could not use simple view as if Espresso would not wait until data is loaded. If you are going to use Espresso.onData(is(instanceOf(CustomExpandableListAdapter.class))) .inAdapterView(withId(R.id.aversionsListView)) then it its will return AdapterListView. If you want to click...
android,junit,gradle,android-emulator,android-espresso
Brief response: This seems a good link about java.lang.IncompatibleClassChangeError. And If you try it on CI: Emulator is not fully booted after wait-for-device, it's not ready for your tests and your app is not installed due a timeout, so there are no tests performed and the build fails as a...
android,listview,android-espresso
Figured this out. class Matchers { public static Matcher<View> withListSize (final int size) { return new TypeSafeMatcher<View> () { @Override public boolean matchesSafely (final View view) { return ((ListView) view).getChildCount () == size; } @Override public void describeTo (final Description description) { description.appendText ("ListView should have " + size +...
android,testing,android-espresso,android-instrumentation
Ok I figured it out. First it is necessary to use the Activity Context provided by getActivity, and then I could use intents to send the activity in background and in foreground, using the HOME category and the FLAG_ACTIVITY_REORDER_TO_FRONT: private void goHome(Activity activity) { Intent intent = new Intent(); intent.setAction(Intent.ACTION_MAIN);...
java,android,android-testing,android-espresso
ActivityInstrumentationTestCase2 is a JUnit3 test case because it extends from TestCase. @Test annotation is a replacement for the test-prefix naming convention used in JUnit3. JUnit4 test classes no longer require to extend TestCase or any of its subclasses. In fact JUnit4 tests cannot extend TestCase, otherwise AndroidJUnitRunner will treat them...
android,android-studio,android-espresso
The solution is very simple, just change this lines in your gradle.build: androidTestCompile 'com.jakewharton.espresso:espresso:1.1-r3' androidTestCompile('com.jakewharton.espresso:espresso-support-v4:1.1-r3') by adding exlude for compatibility library: androidTestCompile 'com.jakewharton.espresso:espresso:1.1-r3' androidTestCompile('com.jakewharton.espresso:espresso-support-v4:1.1-r3') { exclude group: 'com.android.support' } ...
I've found the solution myself. The main issue - StickyListHeadersListView is a wrapper around ListView, it doesn't extend ListView. So we can't work with adapter directly, but we can do this: onData(anything()).inAdapterView(allOf( isAssignableFrom(AdapterView.class), isDescendantOfA(withId(R.id.list)), isDisplayed())) .atPosition(1).perform(click()); ...
I figured it out, I used a custom viewAction public static ViewAction swipeForTextToBeVisible(final String text, final long millis, final View navigationView) { return new ViewAction() { @Override public Matcher<View> getConstraints() { return isRoot(); } @Override public String getDescription() { return "swipe for a specific view with text <" + text...
Asserting something against a view that belongs to a certain activity is in my opinion a very elegant way of checking if that specific activity has been started. From the official docs: At the same time, the framework prevents direct access to activities and views of the application because holding...
android,testing,android-espresso,ui-testing
I don't think there is any easy, elegant solution to this. The 90% constraint is hardcoded in GeneralClickAction, and the class is final so we can't override getConstraints. I would write your own ViewAction based on GeneralClickAction's code, skipping the isDisplayingAtLeast check....
It's possible to enable keyword asserts, but it requires a manual step, and it would be unusual to use keyword asserts in test code. It's best to use the JUnit methods (assertTrue, etc.) as you would in unit tests....
android,testing,textview,android-espresso
helped me: onView(withId(R.id.password)).check(matches(withError( getActivity().getString(R.string.incorrect_data)))); private static Matcher<View> withError(final String expected) { return new TypeSafeMatcher<View>() { @Override public boolean matchesSafely(View view) { if (!(view instanceof EditText)) { return false; } EditText editText = (EditText) view; return editText.getError().toString().equals(expected); } @Override public void describeTo(Description description) { } }; } ...
android,android-viewpager,android-espresso,ui-testing
FirstVal, ViewPager is not an AdapterView, it directly extends from ViewGroup. So the method onData() cannot be used on a ViewPager. 1. Solution As it's a ViewGroup, each items are direct children of its ViewPager. So the process is to reference the first view child using a custom matcher (like...
android,android-gradle,android-espresso
Starting from Espresso 2.0 you need to use android.support.test.runner.AndroidJUnitRunner as you default runner Setup instructions can be found here...
java,android,eclipse,ant,android-espresso
The error you're seeing is caused by the third-party jar not being packaged inside the APK. The default behaviour of the android ant build is that only the jars found in application project /libs folder are packaged into the apk. Copy the espresso-1.1-bundled.jar to the /libs folder of the app...
UPDATE: Use Espresso 2.0 for Lollipop support https://code.google.com/p/android-test-kit/wiki/EspressoSetupInstructions Yes, if you remove "message.recycle(); " and rebuild it will solve that problem. The Espresso team announced at GTAC that the next release of Espresso will be in AOSP before too long. See video here: https://www.youtube.com/watch?v=aHcmsK9jfGU ( I was the original poster...
android,android-fragments,android-viewpager,fragmentstatepageradapter,android-espresso
Turns out that I wasn't really using AsyncTask for api calls. I'm using Retrofit and had the following: if (ActivityManager.isRunningInTestHarness()) { d(TAG, "Using AsyncTask thread pool executor!"); adapter.setExecutors(AsyncTask.THREAD_POOL_EXECUTOR, new MainThreadExecutor()) .build(); } else { d(TAG, "Using nonAsyncTask thread pool executor!"); adapter.setClient(new OkClient(getBaseClient())); } ActivityManager.isRunningInTestHarness() did not return true when executing...
android,intellij-idea,gradle,android-espresso,ui-testing
I have found an workaround: use android-studio based on the community edition of intelliji idea instead of the premium version of intelliji idea. Create a new project and set up espresso from there. More detail refer to the gradle files in the sample project: Hope it helps. http://developer.android.com/sdk/index.html...
android,android-testing,dagger,android-espresso
This issue had me for a bit. You likely need to exclude javax.inject from the espresso dependency. Earlier versions of Android appear to be less tolerant of identical dependencies. Something along the lines of: androidTestCompile ('com.android.support.test.espresso:espresso-core:2.0') { exclude group: 'javax.inject' } Beware that this can bite you all over the...
No, I don't think there's a clean/easy way to get the current Activity from outside of a test. However, you could do this cleanly with a custom view matcher. Something like static Matcher<View> withSelectedItemPosition(final int selectedItemPosition) { return new BoundedMatcher<View, Spinner>(Spinner.class) { @Override protected boolean matchesSafely(Spinner spinner) { return spinner.getSelectedItemPosition()...
java,android,android-testing,android-espresso,android-instrumentation
Thanks to @Gordak. His answer has almost worked. But, unfortunately, it blocks the main thread so the test never ends. I modified it a little bit so now it works. @Before public void setUp() throws Exception { activity = testRule.getActivity(); latch = new CountDownLatch(1); } @Test public void testSimpleSetup() {...
android,android-testing,android-espresso
Actually idling resources are most difficult points of Espresso. You should implement it if in your test you have to wait for/sync with some asynchronous background task. By default, Espresso waits for UI operations in the current message queue to process and default AsyncTasks(synchronizes with the default AsyncTask thread pool)...
android,android-testing,android-espresso
The issue was actually caused by the espresso-support library. I needed to add com.squareup.dagger as an exclusion there too while I was only adding exclusions to the other library. androidTestCompile('com.jakewharton.espresso:espresso:1.1-r3') { exclude group: 'com.squareup.dagger' } androidTestCompile ('com.jakewharton.espresso:espresso-support-v4:1.1-r3') { exclude group: 'com.squareup.dagger' // this goes here too exclude group: 'com.android.support', module:...
withId is only one of view matchers. You could you use others that are suitable for you case. You could check under ViewMatchers of com.google.android.apps.common.testing.ui.espresso.matcher. Google code could be found here. Also hamcrest matchers could help to have more complex conditions. One of samples could be this: onView(allOf(isAssignableFrom("class name"), withText("Text...
Looks like that you have a dialog displayed on top of the activity when espresso is trying to find a view. Take a look at the View Hierarchy dump that is outputted in the espresso exception to figure out what dialog it is and why it's showing up....
android,gradle,android-espresso
You have a build.gradle file inside your app folder. In that file you can configure your project, "dependencies" and other options. It's very similar to maven. You have another build.gradle file in your root folder from your project. This conf file is more general and call the other build.gradle file....
Note that you are using the deprecated ActivityInstrumentationTestCase2 and that TestCases like ActivityInstrumentationTestCase2 or ServiceTestCase are deprecated in favor of ActivityTestRule or ServiceTestRule. So try switchwing to using the rules, which is actually pretty straightforward. Also, be sure to use the correct annotations. Check my other answer here to get...
android,testing,android-espresso
Try this. onData(anything()).inAdapterView(withId(R.id.list_view)).atPosition(0).perform(click()); ...
You might need to rebuild the project. In Android Studio: Build -> Rebuild project. If it doesn't help run the following gradle task (given that you have a wrapper and your module name is "app"): ./gradlew app:dependencies and make sure your androidTest tasks contain espresso dependencies....
android,testing,junit,android-espresso
You have to update the test "Edit Configuration" and include the AndroidJUnitRunner as the instrumentation runner. I found the solution in this video: https://youtu.be/TGU0B4qRlHY?t=9m36s...
The trick to set a sleep time in setup method before it executes the test methods. ` public void setUp(){ super.setUp(); try { Thread.sleep(1000); } catch (InterruptedException e) { e.printStackTrace(); } } `...
android,integration-testing,android-espresso
Uff, I forgot to exclude support library in the gradle file :( Here's the correct build.gradle file apply plugin: 'android' android { packagingOptions { exclude 'LICENSE.txt' exclude 'META-INF/LICENSE' exclude 'META-INF/LICENSE.txt' exclude 'META-INF/NOTICE' } compileSdkVersion 19 buildToolsVersion "19.0.3" defaultConfig { minSdkVersion 8 targetSdkVersion 19 versionCode 1 versionName "1.0" testInstrumentationRunner "com.google.android.apps.common.testing.testrunner.GoogleInstrumentationTestRunner" }...
android,android-studio,android-gradle,android-espresso
It showed that Espresso is still not Gradle-ready. So I used Double Espresso the Gradle-friendly port of Espresso, and it seems to be working.
This slightly long statement works for me: import static android.support.test.espresso.assertion.ViewAssertions.matches; import static android.support.test.espresso.matcher.RootMatchers.withDecorView; import static android.support.test.espresso.matcher.ViewMatchers.isDisplayed; import static android.support.test.espresso.matcher.ViewMatchers.withText; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; .......
android,dependency-injection,functional-testing,dagger,android-espresso
Your approach doesn't work because it only happens once, and as Matt mentioned, when the activity's real injection code runs, it will wipe out any variables injected by your special object graph. There are two ways to get this to work. The quick way: make a public static variable in...
android,android-testing,android-espresso
Please see my update on the bug. In short, you need this line: android { testBuildType "develop" } ...
I solved this by identifying a unique ancestor view. onView(allOf(isDescendantOfA(withId(R.id.someParent)), withId(textViewId))) .perform(scrollTo(), myAction); ...
android,rx-java,android-espresso
Wrote a little integration piece between RxJava Plugins and Espresso. Hope this helps someone else. https://gist.github.com/digitalbuddha/d886eae1578bca78b9bf...
android,testing,android-intent,dependencies,android-espresso
You also need androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2' See https://code.google.com/p/android-test-kit/wiki/EspressoIntentsSetupInstructions for more information....
android,unit-testing,android-studio,android-espresso
Your test is missing @Test annotation. So as your setup method is missing @Before
java,android,testing,gradle,android-espresso
it helped me - https://github.com/bryanstern/dagger-instrumentation-example/issues/1 I must to add some code to build.gradle: debugCompile 'com.google.dexmaker:dexmaker-mockito:1.0' debugCompile 'com.google.dexmaker:dexmaker:1.0' debugCompile 'org.mockito:mockito-core:1.10.17' debugCompile ('com.android.support.test.espresso:espresso-core:2.0') { exclude group: 'javax.inject' } debugCompile 'com.android.support.test:testing-support-lib:0.1' ...
android,android-studio,android-testing,android-espresso
Change the Test Artifact within your Build Variants to Android Instrumentation Tests. The Build Variants tab can be found in the bottom left side of the Android Studio window above Favorites. Clicking on the tab should open a pane with your modules and build variants for those modules. Above the...
It was a bug in my app code, where SwipeRefreshLayout animated itself indefinitely. Due to a bug in this component, the refresh state was not even showing.
android,unit-testing,integration-testing,android-espresso
ActivityTestRule comes with the beforeActivityLaunched method which you can override and it will be called right before activity is launched. EDIT: Turns out that Application onCreate is called after Instrumentation onCreate(). In this case you may create your custom test runner which will extend AndroidJUnitRunner and will override the callApplicationOnCreate()...
android,junit4,robotium,android-testing,android-espresso
You can use a helper function to get the id: private static int getId(String id) { Context targetContext = InstrumentationRegistry.getTargetContext(); String packageName = targetContext.getPackageName(); return targetContext.getResources().getIdentifier(id, "id", packageName); } Then you can use the id in Espresso: onView(withId(getId("button"))).perform(click()); ...
android,integration-testing,retrofit,android-espresso
The most straightforward solution for this: is to basically swap out Retrofit's Thread-pool executor with an AsyncTask one (as recommended by the very helpful Nick from that linked Google group discussion). I do this like so: new RestAdapter.Builder() .setEndpoint(LOCLSET_SERVER_URL) .setExecutors(AsyncTask.THREAD_POOL_EXECUTOR, new MainThreadExecutor()) .build(); I'm not sure if this is the...
android,testing,android-espresso,kotlin
You can get context from InstrumentationRegistry by calling the getTargetContext() method.
android,gradle,roboguice,android-espresso,robolectric-gradle-plugin
You can figure out what is pulling in dependencies by running this command in your project root: ./gradlew app:androidDependencies You will get output similar to this: Also, don't forget to check your app/libs/ folder to ensure it's empty if you're pulling everything in with Gradle....
android,junit4,android-testing,android-espresso
You need an IdlingResource with an isIdleNow() that returns true only if the specific amount of time has passed. To achieve that, save the start time and compare it with current time: public class ElapsedTimeIdlingResource implements IdlingResource { private final long startTime; private final long waitingTime; private ResourceCallback resourceCallback; public...
You didn't really provide a question here, so I assume the question is about why this setup is not working as expected. There are (at least) two reasons: The assert assertTrue(getActivity().isDidThreadReturn());in testThreadRetrieval() does not wait at all for IdlingResources to be finished. Only ViewInteraction.check() and ViewInteraction.perform() are aware of those...
java,android,android-gradle,build.gradle,android-espresso
Update (6/04/2015): With the latest release of runner 0.3 and rules 0.3, this answer is no longer needed. You can simply use androidTestCompile 'com.android.support.test:runner:0.3' androidTestCompile 'com.android.support.test:rules:0.3' androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2' with latest support libraries. (22.2.0 as of this writing) Update (5/30/2015): compile 'com.android.support:appcompat-v7:22.2.0' androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2' //...
android,networking,android-espresso,idle-processing
Like the other answer suggests, the countingIdlingResource does not really apply for your use case. What I always do is add an interface - let's call this one ProgressListener - as a field of the activity / fragment that has a resource to be waited on (asynchronous background work, longer...
android,junit4,android-testing,android-espresso,ui-testing
This worked for me onData(allOf()).atPosition(0). onChildView(withId(R.id.rcOverflow)). perform(click()); ...
android,android-animation,android-permissions,android-espresso,android-instrumentation
I finally got this to work. Here is a Gist listing the required steps: https://gist.github.com/daj/7b48f1b8a92abf960e7b The key step that I had missed was running adb to grant the permission: adb shell pm grant com.mypackage android.permission.SET_ANIMATION_SCALE Adding the permission to the manifest and running the reflection steps did not seem to...
android,selenium,appium,android-espresso
If you have already installed android sdk and configured path skip step 1. Step1: To configure your sdk path in .bashrc file Type gedit .bashrc at terminal Opens an text editor, type the folowing and save export ANDROID_HOME="$HOME/adt/sdk" export JAVA_HOME="/usr/bin/java" export PATH=${PATH}:~/adt/sdk/tools export PATH=${PATH}:~/adt/sdk/platform-tools Step2: Then type uiautomatorviewer at your...
android,junit4,robotium,android-testing,android-espresso
You can use the same reflection technique to specify the class in ActivityTestRule: @RunWith(AndroidJUnit4.class) public class MainActivityTest { private static final String CLASSNAME = "com.rex.binderapps.RecorderActivity"; private static Class<? extends Activity> activityClass; static { try { activityClass = (Class<? extends Activity>) Class.forName(CLASSNAME); } catch (ClassNotFoundException e) { throw new RuntimeException(e); }...
android,android-fragments,android-espresso
If you really want to do this, you can do FragmentManager fragmentManager = getActivity().getFragmentManager() and get information about the backstack from fragmentManager. If your fragment has a tag, you could assert that findFragmentByTag(tag) returns something non-null. But it's normally better to make assertions about the view hierarchy. It's what Espresso...
testing,android-espresso,gui-testing,ui-testing
As @Daniel suggested, I created a custom version of MotionEvents, because when using multiple fingers you have to inject ACTION_POINTER_DOWN/UP instead of ACTION_DOWN/UP. And I created a twoFinger version of LinearSwipe, like this: private static Swiper.Status sendLinearSwipe(UiController uiController, float[] startCoordinates, float[] startCoordinatesSecondFinger, float[] endCoordinates, float[]endCoordinatesSecondFinger, float[] precision, float[] precisionSecond, int...
If at the bottom of the ScrollView you need to find a view and match something against it, then simply perform the scrollTo() action on it, before any other actions that require it to be displayed. onView(withId(R.id.onBottomOfScrollView)) .perform(scrollTo(), click()); Note: scrollTo will have no effect if the view is already...
android,android-gradle,android-espresso,buildconfig
One way to reliably find out whether your app is running instrumented by your test suite is to try to load a test suite class: private boolean isInstrumentedRun() { boolean result; try { getApplication().getClassLoader().loadClass( "my.fully.qualified.TestProjectClass"); result = true; } catch (final Exception e) { result = false; } return result;...
android,android-testing,android-espresso
"pressKey" expects a KEYCODE, not a FLAG. So pressKey(KeyEvent.FLAG_EDITOR_ACTION) doesn't really make sense and will definitely not work. But there is a ViewAction for pressing the editor (IME) action, see the static method: ViewActions#pressImeActionButton() You can view the Espresso 1.x implementation details here: https://android-test-kit.googlecode.com/git-history/master/espresso/lib/src/main/java/com/google/android/apps/common/testing/ui/espresso/action/EditorAction.java?r=master...
android,android-espresso,android-instrumentation
Use an if to perform the test only when the user hasn't previously logged in. Then you can add an else to also test the logged status. Otherwise, you have to try and catch the NoMatchingViewException to tell your app not to perform the login test in case of logged...
android,google-maps,android-espresso
Short Answer: With espresso is not really possible. A solution might be to use UIAutomator: https://developer.android.com/tools/testing-support-library/index.html#UIAutomator https://developer.android.com/training/testing/ui-testing/uiautomator-testing.html So you need to: 1) add gradle dependencies: dependencies { androidTestCompile 'com.android.support.test:runner:0.2' androidTestCompile 'com.android.support.test:rules:0.2' androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.0' } 2) make sure you add at...
Ok, I got it. I have to use default constructor as below: public StartActivityTest() { super(StartActivity.class); } That fixed problem....
android,android-bluetooth,android-testing,android-espresso
You can use UIAutomator for this purpose. It is possible to combine Espresso tests with UIAutomator in one test case. The only limitation is that it requires API level 18+ which can be achieved by adding flavor in your build.gradle file.
android,testing,android-espresso
You have to notify callback that you are on the way to idle state, something like that: @Override public boolean isIdleNow() { if (!imageView.isShown()){ if (callback != null) { callback.onTransitionToIdle(); } return true; } return false; } ...
It seems to me that your button is not visible for the moment when you are checking if it is enabled or not. Could it be that are checking on window/button which is not activated yet? It could also be that operations are not synchronized and you have to wait...
java,android,gradle,renderscript,android-espresso
OK, so I used a little hack to fix this problem. The hack is to have a flag class (can be empty) in androidTest->java->com (location is not particular but is important to be part of androidTest). Something like this: public class TestsRunningFlag { } Then have an utility method that...
android,android-espresso,ui-testing
Combined with CommonsWare's answer. Here is my solution: I defined an AtomicBoolean variable and a function to check whether it's running test: private AtomicBoolean isRunningTest; public synchronized boolean isRunningTest () { if (null == isRunningTest) { boolean istest; try { Class.forName ("com.just10.android.Just10TestConfig"); istest = true; } catch (ClassNotFoundException e) {...
android,android-gridview,android-espresso
Your error message tell you have multiple views in your activity that extends form AdapterView so you have another ListView or GridView in your layout. You can either select the AdapterView on the data layer. So select this AdapterView with items of type ItemModel onData(is(instanceOf(ItemModel.class))).atPosition(0) .onChildView(withId(R.id.item_image)).perform(click()); or you can choose...
android,testing,android-espresso
You can download JARs here: https://code.google.com/p/android-test-kit/source/browse/#git%2Fbin%2Fespresso2.0 You probably want espresso-core-2.0.jar. You might also want to download the sources jar so that you can easily see what espresso methods are doing, but it's not required. espresso-contrib-2.0.jar has some extra utilities which you may or may not find useful. That said, I...
android,android-5.0-lollipop,android-4.0,android-testing,android-espresso
Answer created from comment: I use: onView(allOf(withText("text"), isDisplayed())).perform(click()) and it works as expected....
android,gradle,android-espresso
I managed to reproduce your situation by setting the wrong android.test.InstrumentationTestRunner in the test configuration. I would suggest checking if you have the correct one -android.support.test.runner.AndroidJUnitRunner- (or none) specified in the Run menu | Edit Configurations. Also, your question's title is somewhat confusing, since from the build gradle dependencies, my...