android-espresso

Espresso: Thread.sleep( );

我是研究僧i 提交于 2020-04-23 10:25:17
问题 Espresso claims that there is no need for Thread.sleep(); , but my code doesn't work unless I include it. I am connecting to an IP. While connecting, a progress dialog is shown. I need a sleep to wait for the dialog to dismiss. This is my test snippet where I use it: IP.enterIP(); // fills out an IP dialog (this is done with espresso) //progress dialog is now shown Thread.sleep(1500); onView(withId(R.id.button).perform(click()); I have tried this code with and without the Thread.sleep(); but

How to use ActivityTestRule when launching activity with bundle?

半世苍凉 提交于 2020-04-18 07:01:07
问题 I am using val activityRule = ActivityTestRule(SingleFragmentActivity::class.java, true, true) and SingleFragmentActivity is a test helper activity class I used from google GithubBrowseSample how can I launch activity with bundle ? 回答1: You can get activity from activityRule and you can set extra data for intent activityRule.activity.intent.putExtra("key",value) 回答2: There are 2 ways of achieve what you would like to. First one, unfortunately, require creating custom ActivityRule , which will

NullPointerException in RecyclerView espresso test on hdpi device

馋奶兔 提交于 2020-04-17 22:53:27
问题 I have the following test written for RecyclerView @Test fun testHomeActivity_recyclerViewIndex0_configurationChange_displaysWelcomeMessageCorrectly() { launch(HomeActivity::class.java).use { onView(isRoot()).perform(orientationLandscape()) onView( atPositionOnView(R.id.home_recycler_view, 0, R.id.welcome_text_view ) ).check(matches(withText(containsString("Welcome")))) } } It gets passed successfully on my real device, but gets failed on Nexus S hdpi emulator device. With the following error

Navigation components - Mocking Navcontroller graph

我只是一个虾纸丫 提交于 2020-04-16 03:47:47
问题 I'm using navigation components and I'm trying to test my Fragment with instrumented test. The fragment has a custom toolbar initialized in onViewCreated method by an extension function. override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) tbBlack.init() } fun androidx.appcompat.widget.Toolbar.init( menuId: Int? = null ) { title = "" menuId?.let { inflateMenu(it) } findNavController().let { it.graph.let { graph -> val

Navigation components - Mocking Navcontroller graph

北城余情 提交于 2020-04-16 03:47:09
问题 I'm using navigation components and I'm trying to test my Fragment with instrumented test. The fragment has a custom toolbar initialized in onViewCreated method by an extension function. override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) tbBlack.init() } fun androidx.appcompat.widget.Toolbar.init( menuId: Int? = null ) { title = "" menuId?.let { inflateMenu(it) } findNavController().let { it.graph.let { graph -> val

Espresso generating FileNotFoundException, when used with Dagger

杀马特。学长 韩版系。学妹 提交于 2020-03-18 10:41:54
问题 I have been wrestling with a legacy Android app, attempting to add testing and proper architecture to it. The app has a main LaunchActivity which runs a series of checks on launch. Originally, the activity was using Dagger to, rather poorly, 'inject dependencies' that the activity would use to run checks. I shifted gears to MVVM, so that I could test the view model separately, without instrumentation, and would only need to inject a mocked view model for UI tests. I followed this article to

Espresso generating FileNotFoundException, when used with Dagger

瘦欲@ 提交于 2020-03-18 10:41:15
问题 I have been wrestling with a legacy Android app, attempting to add testing and proper architecture to it. The app has a main LaunchActivity which runs a series of checks on launch. Originally, the activity was using Dagger to, rather poorly, 'inject dependencies' that the activity would use to run checks. I shifted gears to MVVM, so that I could test the view model separately, without instrumentation, and would only need to inject a mocked view model for UI tests. I followed this article to

Android Espresso : cannot resolve symbol AndroidJUnit4.class

…衆ロ難τιáo~ 提交于 2020-02-26 07:13:38
问题 I'm trying to create Espresso UI test inside the new Android project but I faced with the following problem. If I tried to create a empty test class: import android.content.Intent; import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; import android.test.ActivityInstrumentationTestCase2; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import static android.support.test.espresso.Espresso.onView; import static android

Android Espresso : cannot resolve symbol AndroidJUnit4.class

北战南征 提交于 2020-02-26 07:12:32
问题 I'm trying to create Espresso UI test inside the new Android project but I faced with the following problem. If I tried to create a empty test class: import android.content.Intent; import android.support.test.rule.ActivityTestRule; import android.support.test.runner.AndroidJUnit4; import android.test.ActivityInstrumentationTestCase2; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; import static android.support.test.espresso.Espresso.onView; import static android

Android - Espresso testing - Close and app and then re-open it?

北城余情 提交于 2020-02-24 05:32:39
问题 In my espresso test, I close the app by using "device.pressBack()". I then want to re-open the app, in a certain Activity, but I'm not quite sure how to do that, since I don't even have a context at this point. Does anybody have an idea? 回答1: OK, got it. You define a rule in your test class: @Rule public ActivityTestRule<MyActivity> myActivityTestRule = new ActivityTestRule<>(MyActivity.class, true, false); Then, after you used device.pressback(), you can use this to open that specific