I am writing an instrumentation test for an assignment for an Android course. I'd like to be able to check that, for example, a TextView
is correctly positioned on the screen. To do this, I want to compare the position of the TextView
to the position of a similar TextView
in a reference implementation; something like this:
onView(withId(R.id.text_view))
.check(isBottomAlignedWith(onView(withId(R.id.text_view_solution))
The issue I'm running into is that R.id.text_view
and R.id.text_view_solution
exist in separate activities. I create two activity rules, one for the assignment solution and one for student submission:
@Rule
public ActivityTestRule<MainActivity> mSubmission = new ActivityTestRule<>(MainActivity.class);
@Rule
public ActivityTestRule<MainActivitySolution> mSolution = new ActivityTestRule<>(MainActivitySolution.class);
Previously, I've been simply getting the activities associated with the above rules and traversing the hierarchy myself to check, but it would be nice to be able to use convenience methods like isBottomAlignedWith
. Additionally, I wanted to switch to Espresso as it's the only way I can find to test in landscape (something I'll also need to do).
However, for some reason, onView
will only search the most recently created activity. So I can find views in MainActivitySolution
but not in MainActivity
. Is there a way do allow Espresso to search both activities for views?
Aucun commentaire:
Enregistrer un commentaire