android-espresso

Click on a specific checkbox in a ListView using Espresso

一笑奈何 提交于 2019-12-13 13:21:05
问题 I have a ListView where each row has a checkbox: Now I want to click on the checkbox in the 4th row. I have the data model for each row, so I can easily use onData() to select a row with the given data. But how do I click on the checkbox in that row? 回答1: If your row layout allows clicking on the row to set the CheckBox, you can use this to click the ListView row: onData(anything()).atPosition(4).perform(click()); Otherwise you can click directly on the CheckBox without knowing its ID: onData

Android Studio can't resolve Espresso 3.0.0

*爱你&永不变心* 提交于 2019-12-13 13:07:05
问题 According to the Android Espresso documentation to date: Add Espresso dependencies To add Espresso dependencies to your project, complete the following steps: Open your app’s build.gradle file. This is usually not the top-level build.gradle file but app/build.gradle. Add the following lines inside dependencies: androidTestCompile 'com.android.support.test.espresso:espresso-core:3.0.0' androidTestCompile 'com.android.support.test:runner:1.0.0' I created a new project and the generated app

How to regain Access on a Activity after sending it to background

蹲街弑〆低调 提交于 2019-12-13 12:29:31
问题 With Espresso I try to test sending an Activity to background, with the Home button and then getting it up in the foreground again to make some checks: @EspressoTest public void test() { onSomeView().check(matches(isDisplayed())); getInstrumentation().sendKeyDownUpSync(KeyEvent.KEYCODE_HOME); Context context = getInstrumentation().getTargetContext(); Intent intent = new Intent(context, MainActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); context.startActivity(intent);

Testing EditText errors with Espresso on Android

て烟熏妆下的殇ゞ 提交于 2019-12-13 11:53:59
问题 I want to test if an EditText field has an error (set with editText.setError("Cannot be blank!")). I've created an Espresso test case with the new AndroidStudio 2.2 feature, to record Espresso tests. So the code is pretty much auto-generated. But for now it only checks if the editText is displayed. @RunWith(AndroidJUnit4.class) public class CreateNoteActivityTitleCannotBeBlank { @Rule public ActivityTestRule<CreateNoteActivity> mActivityTestRule = new ActivityTestRule<>(CreateNoteActivity

How to click on specific list view item child view

霸气de小男生 提交于 2019-12-13 08:07:59
问题 I am trying to click on a specific child view in a list view item. Consider ListView with items. Each item is a compound view with child views. I want firstly select specific list item and than use this item view find child with a specific id and perform a click. Here is my code for getting list item, but I have tried to continue this chain further to achieve desired goal, but I can't find proper methods. onData(anything()).inAdapterView(withId(R.id.list_view_books)).atPosition(0).?? Could

Unable to toggle airplane mode, espresso

喜夏-厌秋 提交于 2019-12-13 07:53:07
问题 I am trying to toggle airplane mode on kitkat version , on rooted emulator. I am using espresso for automation and i have scenario in which i have to switch on airplane mode and do some kind of steps in the app I have modified time using the following method : public static void amTime() { try { Process su = Runtime.getRuntime().exec("su"); DataOutputStream outputStream = new DataOutputStream(su.getOutputStream()); outputStream.writeBytes("date -s 20181015.070000"); outputStream.flush();

Espresso tested view is below dialog and therefore Espresso can't find it

て烟熏妆下的殇ゞ 提交于 2019-12-13 07:27:20
问题 I want to verify that there's a view on the UI that mathces some arbitary text. Therefore I'm using: onView(withId(R.id.my_view_id)).check(matches(withText("my text"))); The problem is though that depending on the battery level of the device there might be a dialog saying that the battery level is low. The dialog that will be shown is a normal AlertDialog . My test runs fine if I don't show the dialog, the moment I'll show it the above espresso statement fails. How can I tell espresso that I

How to validate whether opened correct activity - Espresso

隐身守侯 提交于 2019-12-13 07:20:54
问题 I created android UI test with espresso and done Button click and opening an Activity. Now I want to validate whether opened correct activity or not. 回答1: Use espresso-intents to validate that. The usage is: intended(hasComponent(NewActivity.class.getName())); You can read this thread for more details on that: Espresso - check which Activity is opened using intent on button press? 回答2: You want get the instance of activity rule which you have register and compare it with the activity which

how to make assert to wait for IdlingResource to assert

China☆狼群 提交于 2019-12-13 05:45:41
问题 I want to use idling resources because I´m using RxJava and EventBus in my app and sometimes my tests fail (I´m thinking that is because that synchronisation). Dependencies: androidTestCompile 'com.android.support.test:runner:0.4' androidTestCompile 'com.android.support.test:rules:0.4' androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1' androidTestCompile 'com.android.support.test.espresso:espresso-intents:2.2.1' androidTestCompile('com.android.support.test.espresso

How can I get Main Thread from Thread.currentThread()?

一曲冷凌霜 提交于 2019-12-13 05:43:32
问题 I am sorry, I have stupid question. I have two threads. Thread_Main and Thread_Simple, in Thread_Main performed method A() and method B(). In Thread_Simple performed method C(). Now: first performed method A(), then performed method C(), then performed method B(), then performed method A(), then performed method C(), then method B(), ... But I want: first performed method A(), then performed method B(), then performed method C(), then A(), B(), C(), ... How can to do it? I just have access to