Issue
I have written a UI Testing framework using Espresso to read CSV files and run certain UI commands. I would like this to be able to run all day and all night testing the UI and calling the API and just trying to break it.
I am using wait(), although I know it is actively discouraged, because the system creates and prints physical paper tickets meaning that espresso tends to move too quickly and because it needs to run for a long time and we don't want millions of tickets created. It's not very efficient to try and stay within the 60 seconds espresso gives you before AppNotIdleException is thrown, so I'm wondering if there is a way to deactivate this or to extend it or to catch the exception and deal with it another way
Solution
It's extremely hacky, and goes against everything mentioned in the Espresso docs (but then again so does the concept itself), but I have found a way around the AppNotIdleException.
public void delayTestsbyMillis(int millis) {
try {
if(millis < 59000)
Thread.sleep(millis);
else {
int numLoop = millis/50000;
for(int i = 0; i < numLoop; i++){
Thread.sleep(50000);
onView(withId(R.id.rolling_news)).perform(click());
}
}
} catch (InterruptedException e) {
e.printStackTrace();
}
}
Since Java won't let us ignore an exception, and because this one is always thrown after 60 seconds of no interaction, I just added a for loop in the event that the specified delay is more than 59 seconds. The loop just divides the specified delay into 50 second chunks and clicks on a view that is static and has no onClickListener, in this case "rolling_news". This has the end effect I was after even if it is really bad practice
Answered By - Richardweber32
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.