android-espresso

Mock server requests Android Espresso UI Testing

这一生的挚爱 提交于 2019-12-19 03:38:04
问题 I am using Espresso to write UI tests for my Android application and would like to mock http requests using MockWebServer. I need to mock authentication responses and sign in the user before the tests are run. Is there a way make the app use mockwebserver so that isntead of making actual requests, I can use respontes enqueued on mockwebserver. So far I have: public class AuthenticationTest { @Rule public ActivityTestRule<Authentication> mActivityTestRule = new ActivityTestRule<>

Scrolling to view was attempted, but the view is not displayed

一世执手 提交于 2019-12-19 02:30:08
问题 With Espresso I try to scroll to a textview inside linearlayout - but I am getting this exception: android.support.test.espresso.PerformException: Error performing 'scroll to' on view 'with id: org.ligi.gobandroid_hd:id/final_points'. at android.support.test.espresso.PerformException$Builder.build(PerformException.java:83) at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:70) at android.support.test.espresso.base.DefaultFailureHandler

Is there any way to know if an activity has been started with Espresso?

走远了吗. 提交于 2019-12-18 21:49:56
问题 I'm doing an Activity transition testing with Espresso but I don't know if this is the best way to do it: public void testStartLogin() { onView(withId(R.id.register)).perform(click()); onView(withId(R.id.login_password)).check(matches(isDisplayed())); onView(withId(R.id.login_show_password)).check(matches(isDisplayed())); } The last two are from the second activity but this looks horrible for me. Is there any different way? 回答1: Asserting something against a view that belongs to a certain

Android Espresso. How to check ErrorText in TextInputLayout

百般思念 提交于 2019-12-18 15:30:16
问题 Basically I am trying to test that after login incorrectly I have an error showing in the email field. The view is: <android.support.design.widget.TextInputLayout android:id="@+id/ti_email" android:paddingEnd="10dp" android:paddingTop="10dp" android:paddingLeft="10dp" android:paddingRight="10dp" android:paddingStart="10dp" android:layout_width="match_parent" android:layout_height="wrap_content"> <EditText android:id="@+id/et_email" android:layout_width="match_parent" android:layout_height=

Test Android Activity with different Application class

大憨熊 提交于 2019-12-18 15:28:11
问题 I´m looking for a way to test an Activity with JUnit4 and the ActivityTestRule, but with a different application class (e.g. mocked or inherited). I was able to get this for library projects using the manifest merge and tools:replace="android:name" on the application tag in the androidTest/AndroidManifest.xml. This however does not work for applications. Any ideas how this can be done? 回答1: You can subclass the AndroidJUnitRunner with your own runner and override newApplication() with your

ActivityTestRule - how to call code before Application's onCreate

北慕城南 提交于 2019-12-18 14:53:16
问题 I am using Espresso 2.1 with ActivityTestRule, and I am looking for a way to set some static flags before onCreate() in my application will be called. I have some init code that I don't want called during instrumentation tests. 回答1: Application onCreate() is called after Instrumentation onCreate() . For this case you need to implement a custom test runner which will subclass AndroidJUnitRunner and will override the callApplicationOnCreate() with your custom setup. public class

ActivityTestRule - how to call code before Application's onCreate

ぃ、小莉子 提交于 2019-12-18 14:53:10
问题 I am using Espresso 2.1 with ActivityTestRule, and I am looking for a way to set some static flags before onCreate() in my application will be called. I have some init code that I don't want called during instrumentation tests. 回答1: Application onCreate() is called after Instrumentation onCreate() . For this case you need to implement a custom test runner which will subclass AndroidJUnitRunner and will override the callApplicationOnCreate() with your custom setup. public class

Updating an EditText with Espresso

情到浓时终转凉″ 提交于 2019-12-18 12:51:11
问题 I'm attempting to update an EditText as part of an Espresso test with: onView(allOf(withClassName(endsWith("EditText")), withText(is("Test")))).perform(clearText()) .perform(click()) .perform(typeText("Another test")); However I receive the following error: com.google.android.apps.common.testing.ui.espresso.NoMatchingViewException: No views in hierarchy found matching: (with class name: a string ending with "EditText" and with text: is "Test") By breaking down the test line I can see that

Espresso, scrolling not working when NestedScrollView or RecyclerView is in CoordinatorLayout

老子叫甜甜 提交于 2019-12-18 11:52:44
问题 It looks like CoordinatorLayout breaks the behaviour of Espresso actions such as scrollTo() or RecyclerViewActions.scrollToPosition() . Issue with NestedScrollView For a layout like this one: <android.support.design.widget.CoordinatorLayout android:layout_width="match_parent" android:layout_height="match_parent"> <android.support.v4.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="wrap_content" app:layout_behavior="@string/appbar_scrolling_view_behavior"> ...

Testing ViewPager with Espresso. How perfom action to a button of an Item?

不问归期 提交于 2019-12-18 10:42:08
问题 I have a ViewPager whith items containing only a picture and a button. I can't successfully interact with the UI of an item (Page) because, except the displayed picture, there is nothing to differentiate (from UI point of view) all items of the ViewPager . I tried to select only one item with a position: onData(is(instanceOf(ItemClass.class))) .atPosition(0) .onChildView(withId(R.id.button)) .perform(click()); causing: NoMatchingViewException: No views in hierarchy found matching: is