android-espresso

Checking if a button is clickable in espresso test, android studio

吃可爱长大的小学妹 提交于 2020-01-13 10:13:33
问题 I am writing tests to determine that a specific button is not clickable or is clickable. However it seems to me that there isn't any method or maybe I can't find a method that can check this feature using Espresso. Can anyone help me ? Thank you 回答1: Why not? You can use isClickable() Matcher. onView(withId(R.id.your_button)).check(matches(isClickable())); 回答2: i always combine more tests for my button @Test public void buttonIsEnabled() { onView(withId(R.id. your_button)).check(matches

Testing RecyclerView if it has data with Espresso

依然范特西╮ 提交于 2020-01-13 09:54:27
问题 I need to write a test to click, let's say on the first item in my RecyclerView. At some cases the RecyclerView will be empty and therefore if I click on the position with 0 index it will fail. How do I write a test like this? To check first if the recyclerView not empty and then click on the specific position? 回答1: There are a little bit different scenarios in question and in the comment. Let's implement the next test scenario: If recycler view does not contain anything, do nothing. If

Testing RecyclerView if it has data with Espresso

萝らか妹 提交于 2020-01-13 09:54:09
问题 I need to write a test to click, let's say on the first item in my RecyclerView. At some cases the RecyclerView will be empty and therefore if I click on the position with 0 index it will fail. How do I write a test like this? To check first if the recyclerView not empty and then click on the specific position? 回答1: There are a little bit different scenarios in question and in the comment. Let's implement the next test scenario: If recycler view does not contain anything, do nothing. If

Android Espresso typeText into EditText in ActionBar

梦想的初衷 提交于 2020-01-12 10:06:05
问题 I have a SearchView in my ActionBar that is inflated from XML <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/action_menu_search" android:showAsAction="always|collapseActionView" android:icon="@drawable/action_bar_search_icon" android:actionViewClass="android.widget.SearchView"/> </menu> I inflate it in my Fragment this way: @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater

Android Espresso typeText into EditText in ActionBar

空扰寡人 提交于 2020-01-12 10:05:08
问题 I have a SearchView in my ActionBar that is inflated from XML <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/action_menu_search" android:showAsAction="always|collapseActionView" android:icon="@drawable/action_bar_search_icon" android:actionViewClass="android.widget.SearchView"/> </menu> I inflate it in my Fragment this way: @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater

Android Espresso typeText into EditText in ActionBar

时光怂恿深爱的人放手 提交于 2020-01-12 10:03:06
问题 I have a SearchView in my ActionBar that is inflated from XML <?xml version="1.0" encoding="utf-8"?> <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/action_menu_search" android:showAsAction="always|collapseActionView" android:icon="@drawable/action_bar_search_icon" android:actionViewClass="android.widget.SearchView"/> </menu> I inflate it in my Fragment this way: @Override public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) { inflater

Android Studio Excessive Memory Usage When Running Espresso UI Tests

China☆狼群 提交于 2020-01-11 10:18:26
问题 I notice that when running Espresso UI tests on an emulated device my system's memory usage increases indefinitely until I restart Android Studio and my emulated device. On inspection I can see that my Android Studio and emulated device memory usage remain constant, yet overall memory usage increases. However I cannot see where the additional memory is assigned in my system monitor. This happens even when running empty tests on a blank activity! Please see code attached I am running Android

Espresso - Check RecyclerView items are ordered correctly

时光总嘲笑我的痴心妄想 提交于 2020-01-11 06:21:11
问题 How to go about checking whether RecyclerView items are displayed in the correct order using Espresso? I'm trying to test it checking it by the text for the title of each element. When I try this piece of code it works to click the element but can't go on to instead of performing a click trying to Assert the text for the element onView(withId(R.id.rv_metrics)).perform(actionOnItemAtPosition(0, click())); When I try to use a custom matcher instead I keep getting the error Error performing

Espresso - Check RecyclerView items are ordered correctly

限于喜欢 提交于 2020-01-11 06:21:11
问题 How to go about checking whether RecyclerView items are displayed in the correct order using Espresso? I'm trying to test it checking it by the text for the title of each element. When I try this piece of code it works to click the element but can't go on to instead of performing a click trying to Assert the text for the element onView(withId(R.id.rv_metrics)).perform(actionOnItemAtPosition(0, click())); When I try to use a custom matcher instead I keep getting the error Error performing

Espresso match first element found when many are in hierarchy

天涯浪子 提交于 2020-01-09 19:19:07
问题 I'm trying to write an espresso function to match the first element espresso finds according to my function, even when multiple matching items are found. Ex: I have a list view with cells which contain item price. I want to be able to switch the currency to Canadian dollars and verify item prices are in CAD. I'm using this function: onView(anyOf(withId(R.id.product_price), withText(endsWith("CAD")))) .check(matches( isDisplayed())); This throws the AmbiguousViewMatcherException. In this case,