Comments (6)
"if onView is called immediately after the action perform(click()) then the
onView will fail since the new widget is not yet visible. "
I believe I've seen similar issues. I have a simple app that have view A and if
you swipe to the right you'll get to view B. On view B there's an extra button
on the action bar which is not presented on view A. If I run my espresso test
and swipe to view B then immediately uses onView() to try to match the button,
it'll fail. UI dump from the log would reveal that the button is not in the
view yet.
I didn't implement as complicated workaround as OP did. A simple
Thread.Sleep(1000) before the onView() call made the test pass.
I don't think onData is applicable here since there is no AdapterView. Neither
is registerIdelresouce as there's no background thread.
Original comment by [email protected]
on 24 Jan 2014 at 1:06
from android-test-kit.
[deleted comment]
from android-test-kit.
I found a little better way.
Pattern of use:
// wait during 15 seconds for a view
onView(isRoot()).perform(waitId(R.id.wizardNext, Sampling.SECONDS_15));
Required Action:
/** Perform action of waiting for a specific view id. */
public static ViewAction waitId(final int viewId, final long millis) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isRoot();
}
@Override
public String getDescription() {
return "wait for a specific view with id <" + viewId + "> during " + millis + " millis.";
}
@Override
public void perform(final UiController uiController, final View view) {
uiController.loopMainThreadUntilIdle();
final long startTime = System.currentTimeMillis();
final long endTime = startTime + millis;
final Matcher<View> viewMatcher = withId(viewId);
do {
for (View child : TreeIterables.breadthFirstViewTraversal(view)) {
// found view with required ID
if (viewMatcher.matches(child)) {
return;
}
}
uiController.loopMainThreadForAtLeast(50);
}
while (System.currentTimeMillis() < endTime);
// timeout happens
throw new PerformException.Builder()
.withActionDescription(this.getDescription())
.withViewDescription(HumanReadables.describe(view))
.withCause(new TimeoutException())
.build();
}
};
}
Original comment by [email protected]
on 21 Mar 2014 at 4:38
from android-test-kit.
Thanks for this. I've improved it by taking any view matcher
public static ViewAction waitToFind(final Matcher<View> viewMatcher, final int
millis) {
return new ViewAction() {
@Override
public Matcher<View> getConstraints() {
return isRoot();
}
@Override
public String getDescription() {
return "wait for a specific view with matcher <" + viewMatcher + "> during " + millis + " millis.";
}
@Override
public void perform(final UiController uiController, final View view) {
uiController.loopMainThreadUntilIdle();
final long startTime = System.currentTimeMillis();
final long endTime = startTime + millis;
do {
for (View child : TreeIterables.breadthFirstViewTraversal(view)) {
// found view with required ID
if (viewMatcher.matches(child)) {
return;
}
}
uiController.loopMainThreadForAtLeast(50);
}
while (System.currentTimeMillis() < endTime);
// timeout happens
throw new PerformException.Builder()
.withActionDescription(this.getDescription())
.withViewDescription(HumanReadables.describe(view))
.withCause(new TimeoutException())
.build();
}
};
}
Though I'm sure this could be implemented in an IdlingResource and then
register it with Espresso
Original comment by [email protected]
on 14 Apr 2014 at 4:00
from android-test-kit.
I tried the solution above. But sometimes, I get the below error:
java.lang.RuntimeException: Action will not be performed because the target
view does not match one or more of the following constraints:
at least 90 percent of the view's area is displayed to the user.
I tried adding constraint like this:
if (viewMatcher.matches(child)&& viewMatcher.matches(isCompletelyDisplayed())
But this timed out. Clearly, suggesting that the function matches with the view
even if it is partially displayed.
Any suggestions for that.
Original comment by [email protected]
on 5 May 2014 at 1:19
from android-test-kit.
The requested waitForView API breaks the Espresso API paradigm (i.e. everything
should be synchronized. The test author should not have to make a decision on
how long to wait for a view). For components that are not synchronized by
default, Espresso provides the IdlingResource interface. Please use it. It will
make your tests much cleaner and more dependable.
Some of you may also be hitting
https://code.google.com/p/android-test-kit/issues/detail?id=55. We will look
into improving this in the coming release.
Original comment by [email protected]
on 7 May 2014 at 6:33
- Changed state: WontFix
from android-test-kit.
Related Issues (20)
- Using onData with an overlaid View won't properly click on items
- Getting DexException when running assembleDebugAndroidTest goal second time HOT 6
- Enhancement: FlakyTest for JUnit4/Espresso HOT 2
- MonitoringInstrumentation leaking activity instances through ExecutorService HOT 3
- withText doesn't find views with textAllCaps attribute used HOT 1
- using onData in RecyclerView HOT 4
- Espresso-contrib cannot inflate RecyclerView with IllegalStateException (Unable to find LayoutManager) HOT 5
- Provide API to list tests that will be run
- Add API for adding RunListeners to AndroidJUnitRunner
- getGlobalVisibleRect works differently on API 22
- longClick() becomes Click()
- Accessibility checks fail tests on pre-Lollipop emulators
- pressBack() doesn't call onBackPressed().
- Migration from googlecode?
- Webview support always times out on first test on devices pre Android 4.4 HOT 2
- Having Guava and espresso-web as androidTest dependencies does not compile
- Swipe action on a view pager fails in Espresso tests on Emulator
- NoMatchingViewException leaks Activity
- onData check for non-selectable list headers doesn't work on API 22
- Espresso won't find View when included with androidTestCompile
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from android-test-kit.