android-espresso

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

梦想的初衷 提交于 2020-02-24 05:32:25
问题 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

Espresso Test Failed: Wanted to match 1 intents. Actually matched 0 intents

。_饼干妹妹 提交于 2020-02-21 13:09:56
问题 I am trying to test that my SplashActivity correctly launches HomeActivity if the user is logged in. I have looked at related questions on StackOverflow, this seems to be a common issue, but I just cannot seem to get anything to work. I have watched the test execute on my device and visually verified that SplashActivity is indeed launching HomeActivity. HomeActivity expects a plain intent with no data. Here is the full error: IntentMatcher: has component: has component with: class name: is

Espresso Test Failed: Wanted to match 1 intents. Actually matched 0 intents

孤街醉人 提交于 2020-02-21 13:08:35
问题 I am trying to test that my SplashActivity correctly launches HomeActivity if the user is logged in. I have looked at related questions on StackOverflow, this seems to be a common issue, but I just cannot seem to get anything to work. I have watched the test execute on my device and visually verified that SplashActivity is indeed launching HomeActivity. HomeActivity expects a plain intent with no data. Here is the full error: IntentMatcher: has component: has component with: class name: is

Espresso onData perform click on multiple items

微笑、不失礼 提交于 2020-02-06 04:09:51
问题 I have a Gridview with an adapter based on a list of pojos of type Tile for my MineSweeper game, Im doing some unit tests and all I want to do is Click on all gridview Items that dont have mines and longclick all items that does have items I have tried with the following: onData(allOf(is(instanceOf(Tile.class)),isMineMatcher(true))) .inAdapterView(withId(R.id.f_minefield_gridview)) .perform(longClick()); onData(allOf(is(instanceOf(Tile.class)),isMineMatcher(false))) .inAdapterView(withId(R.id

Clicking on one of many views with same id in Espresso

生来就可爱ヽ(ⅴ<●) 提交于 2020-02-05 13:37:42
问题 I have a layout (A) that includes another layout (B) multiple times. Layout B contains a button with id R.id.my_button . As a result, layout A contains many of those buttons with the same id. How do I test clicking on any of those buttons with espresso? onView(withId(R.id.my_button)).perform(click()); doesn't really do anything in this case. 回答1: Probably, your layout B contains also some unique information, let's say TextView with unique name . In this case your code will look like this:

Android Studio Instrumentation testing build variant

扶醉桌前 提交于 2020-01-29 02:39:50
问题 So I am trying to write instrumentation tests using a custom build variant, mock. In this build variant I mocked up my classes and server. When I try using the mock build myself it works fine, but I can't seem to use my mock build for testing. Here's what my configuration looks like inside Android Studio. I had some issues getting my tests to run so I tried to uninstall all versions of my app except my mock version and I keep getting this error: Test running startedTest running failed: Unable

Espresso test Fail

China☆狼群 提交于 2020-01-24 19:31:09
问题 I am doing some Espresso testing in Android. The test is failing with this error: java.lang.ClassCastException: androidx.fragment.app.testing.FragmentScenario$EmptyFragmentActivity cannot be cast to com.stavro_xhardha.pockettreasure.MainActivity This is my test method: @Test fun toolbarTitle_shouldContainCorrectInput() { val mockNavController = mock(NavController::class.java) val fragmentScenario = launchFragmentInContainer<SetupFragment>() fragmentScenario.onFragment { Navigation

Complete LoginTest does not run in android using espresso

折月煮酒 提交于 2020-01-24 00:56:05
问题 I am using espresso and ui automation for test cases and generating report by running gradlew.bat :app:createDebugCoverageReport in command prompt. My Problem:- I am having LoginTest activity which contains 4 or 5 methods in it.Methods are named in sorting order using @FixMethodOrder(MethodSorters.NAME_ASCENDING) .When i run the command gradlew.bat :app:createDebugCoverageReport in command prompt it runs one method only,after completion stop the app.For example :- It runs aa_doLogin() only

Espresso: Why don't spinners close after selection?

爱⌒轻易说出口 提交于 2020-01-21 09:26:30
问题 I have a question about selecting items in Spinners with Espresso. Or to be more exact: The selection works, but after that the view assertions fail because the spinner is still open. Let's say I have a really simple activity that contains a spinner and a textview that shows the selection, like this: Now, I wrote an Espresso test that selects 'dogs' and verifies the textview is updated accordingly: @Test public void selectDogs() throws Exception { onData(allOf(is(instanceOf(String.class)), is

E/TestRunner: android.database.sqlite.SQLiteException: no such table: Censored (code 1 SQLITE_ERROR)

别等时光非礼了梦想. 提交于 2020-01-17 14:08:27
问题 I have an Android app with over 50 Espresso test cases. Most of the time the tests work correctly, but during some runs, one test case (only one) fails with a missing database table. All the other test cases use this table correctly. Sometimes the error message is different, such as: android.database.sqlite.SQLiteDiskIOException: disk I/O error (code 522 SQLITE_IOERR_SHORT_READ) Code samples available on request, but it's a massive app so I doubt I could fit it all into a post. Should I just