android-espresso

Android Espresso : correctly test closing app with pressBack

拜拜、爱过 提交于 2019-12-12 14:17:27
问题 I'm trying to implement some navigation tests with espresso. Actually i want to check if the application has been closed by the use of the Back key on the main screen, just after a fresh start. Here is a piece of code i'm using. class NavigationTests { @get:Rule val mActivityTestRule: ActivityTestRule<MainActivity> = ActivityTestRule(MainActivity::class.java) @Test fun backOnEmptyHomeMustExit(){ Espresso.pressBack() Assert.assertTrue(mActivityTestRule.activity==null) } } Actually i got a test

Dismiss Alert Dialog in Android Espresso Test

。_饼干妹妹 提交于 2019-12-12 10:46:43
问题 I've looked around for solution for this but can't find one. I'm creating an Espresso Test and need to dismiss an Alert Dialog that appears in the middle of the screen the first time a particular Activity screen is displayed. There are no buttons on the dialog so to dismiss it the user needs to click anywhere outside the box. Does anyone know how I can do this with Espresso. I tried clicking on a layout on the underlying screen but Espresso fails saying that view cannot be found in the

Accessing a RadioButton and selecting it in Espresso

牧云@^-^@ 提交于 2019-12-12 10:42:05
问题 I am using Espresso to test an Android application. I am having trouble trying to find a way to access and select a RadioButton (which belongs to a RadioGroup) of the current Activity. Does anyone have any suggestions? Thanks you -Andrew 回答1: Given the following layout: <RadioGroup android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/radioGroup" > <RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string

Espresso test passes individually, fails when run in the suite

折月煮酒 提交于 2019-12-12 08:37:46
问题 I have the following Espresso test. It always passes if I run it by itself, but always fails when I run all the tests in the class together. What's also a bit strange is that it used to work even as part of the suite. I'm not sure why now it stopped working. It must be something I've done but I don't know what. @Test public void itemHasImage_ShowsImage() { closeSoftKeyboard(); if (mItem.getImageUrl() != null) { onView(withId(R.id.edit_item_image)).perform(scrollTo()) .check(matches

Espresso Recyclerview scroll to end

冷暖自知 提交于 2019-12-12 08:33:57
问题 I have an Android application which has a RecyclerView with N elements, and when this RecyclerView reaches to end when scrolling, then more elements are added (so, it's an infinite list which loads data when scroll reached the bottom). I would like to test this, but I haven't found a way to do this. I use RecyclerViewActions which have scrollToPosition but even if I put the last position, the end is not reached (because the height of each element is high). Anybody know how could I do this?

Android Test Orchestrator not working with Android X

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-12 08:26:46
问题 I have recently migrated my project to use AndroidX, and have configured test orchestrator for my espresso tests on gradle using the following docs: https://developer.android.com/training/testing/junit-runner#using-android-test-orchestrator I have the dependency: androidTestUtil 'androidx.test:orchestrator:1.1.0-beta01' However, none of my tests are executed and looks like they fail when running gradle runs the following adb shell command i.e: adb shell 'CLASSPATH=$(pm path android.support

Espresso testing disable animation

假装没事ソ 提交于 2019-12-12 07:45:35
问题 @Test public void test3_PaySuccessful(){ init(); ViewInteraction amountEditText = onView( allOf(withId(R.id.et_amount), isDisplayed())); amountEditText.perform(replaceText("SGD 0.010"), closeSoftKeyboard()); //, withText("Proceed") ViewInteraction appCompatButton = onView( allOf(withId(R.id.btn_confirm), isDisplayed())); appCompatButton.perform(click()); //, withText("Pay") ViewInteraction appCompatButton2 = onView( allOf(withId(R.id.btn_confirm), isDisplayed())); appCompatButton2.perform

Can't select Test class in Edit Configuration

情到浓时终转凉″ 提交于 2019-12-12 06:59:07
问题 I have created an Espresso/UIAutomator unit test. However, when I try to run it, Android Studio won't recognize it. The button to select TestLogin.java is greyed out. I'm using Android Studio 2.0 preview 5. package com.greenrobot.yesorno.test.TestLogin import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; import android.test.suitebuilder.annotation.LargeTest; import org.junit.Rule; import org.junit.Test; import org.junit1.runner.RunWith; import

Mock injected ViewModel

蓝咒 提交于 2019-12-12 05:48:50
问题 I need to run Android instrumented test on StarterActivity . Here is how it goes public class StarterActivity extends BaseActivity<ActivityStarterBinding> { @Inject protected StarterViewModel starterViewModel; @Override public int getContentView() { return R.layout.activity_starter; } @Override protected void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); getApplicationComponent().inject(this); } //... } And I call for starterViewModel method in onStart.

Android UI testing with Espresso on an AlertDialog inner views

非 Y 不嫁゛ 提交于 2019-12-12 05:10:30
问题 I'm testing a click on an AlertDialog's inner ListView using Espresso but keep getting NoMatchingViewException. The Dialog has a ListView that reads the accounts in the device. AlertDialog.Builder builder = new AlertDialog.Builder(activity_reference); builder.setTitle(R.string.main_dialog_title); ListView lv = new ListView(activity_reference); ArrayAdapter<String> adapter = new ArrayAdapter<String> (activity_reference, android.R.layout.simple_list_item_1, android.R.id.text1, gUsernameList);