• 9
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

I want to write an Espresso test that will use currently launched activity on my tablet's screen. So I'll manually navigate to this activity with appropriate content prior launching the test, cause it's difficult and reluctant to write additional code to launch this activity with the same global "state" in app and pass all needed params in the launching intent and so one.

Is it possible and how to do this with Espresso, or I have to use UI Automator then?

      • 1
    • Can you provide an example of exactly what actions you want to take? If it's just opening the app and navigating to an activity, as a user would, then that shouldn't be a problem with Espresso.
      • 2
    • A Droid, I wanted Espresso test to fill a lot of input fields on the page, but I'll open needed page (activity) manually before running the test. But it seems Android Studio "relaunching" my app too when I'm running the test.
      • 2
    • @Mike what you intend defeats the whole idea of automated testing... and is probably more waste of time than writing test-rules once and then simply using them, while getting fresh coffee. besides, it might also distort the accuracy of the results.
      • 1
    • @Mike you can do this for that first of all you have to open needed activity and from that activity, you have to just write onView(withId(Id of view)).perform(click()) method to open activity which will be having multiple input fields.
      • 1
    • @Mike When you run test case it will always launch the app so manually opened screen will not work in any case you must have to open that screen Or activity from a test case.

If you absolutely do not want to set up the intent to launch the activity you want to test then you can just use a breakpoint in your test. This will allow you to manually navigate to the activity before your Espresso tests start executing. I would say, however, that at the very least you should use Espresso to automate those manual steps.

@Test
fun testActivityIsDisplayed() {
    openTestActivity() //automate with espresso or put breakpoint to do manually
    onView(withId(R.id.testActivity)).check(matches(isDisplayed()))
}

private fun openTestActivity() {
    ...
}
  • 1
Reply Report
      • 1
    • Okay, seems that only way that possible here. I'll think about launching with intent, although this idea is bothering me cause activity somewhere in the middle, not the screen that can be called externally