android


Idling resource exits even when isIdleNow() returns false in espresso


I have an idling resource which is supposed to tell espresso to wait for 140 seconds. the first time i run the test, it was working. but subsequent runs fails. that is, my test exist without waiting for 140 seconds even when isIdleNow() returns false. what could be the cause?
#RunWith(AndroidJUnit4.class)
public class MainTest {
#Rule
public ActivityTestRule<Main> activityRule = new ActivityTestRule<>(Main.class);
private static Context getContext() {
return InstrumentationRegistry.getInstrumentation().getTargetContext();
}
private static Context getTestContext() {
return InstrumentationRegistry.getInstrumentation().getContext();
}
#Test
public void waitForSomeSeconds() {
long minutesInMills = DateUtils.SECOND_IN_MILLIS;
long waitTime = minutesInMills * 10;
waitFor(waitTime);
}
private void waitFor(long waitingTime){
IdlingPolicies.setMasterPolicyTimeout(waitingTime * 14, TimeUnit.MILLISECONDS);
IdlingPolicies.setIdlingResourceTimeout((waitingTime * 14), TimeUnit.MILLISECONDS);
// Now we wait
IdlingResource idlingResource = new ElapsedTimeIdlingResource(waitingTime*7);
Espresso.registerIdlingResources(idlingResource);
onView(withId(R.id.mInstructions))
.perform(typeText("ok time up!"),closeSoftKeyboard());
// Clean up
Espresso.unregisterIdlingResources(idlingResource);
}
public void setMessage(String message){
this.message = message;
}
}
My idling resource
public class ElapsedTimeIdlingResource implements IdlingResource {
private final long startTime;
private final long waitingTime;
private ResourceCallback resourceCallback;
public ElapsedTimeIdlingResource(long waitingTime) {
this.startTime = System.currentTimeMillis();
this.waitingTime = waitingTime;
}
#Override
public String getName() {
return UUID.randomUUID().toString();
}
#Override
public boolean isIdleNow() {
long elapsed = System.currentTimeMillis() - startTime;
Log.d("Idling", " elasped time is " + elapsed + " waiting time is " + waitingTime);
boolean idle = (elapsed >= waitingTime);
Log.d("Idling", " idel is " + idle);
if (idle) {
resourceCallback.onTransitionToIdle();
}
return idle;
}
#Override
public void registerIdleTransitionCallback(ResourceCallback resourceCallback) {
this.resourceCallback = resourceCallback;
}
}

Related Links

Receiving bluetooth signal and sending text message in Android programming
Android and Sails js application to talk to each other
What will be the value of TAG?
What is the difference between MeasureSpec.getSize(widthMeasureSpec) and getWidth()?
Paths on canvas: Small gap between oblique lines or straight lines not on one level? (FILL or FILL_AND-STROKE)
App not working in all devices
ListView ContextAction not following layout
Android Facebook sdk 4.0 : Null exception while getting facebook user information?
Get eNb adn SNR in LTE network
Android Facebook SDK Login work only for my account
My Imageview Stops moving after scaling on Max level
how to prevent my app for video recording [closed]
Cordova location permission triggers onResume every time
Get value of selected radio button which is saved in Firebase, and set it as default state in user profile
file is encrypted or is not a database: , while compiling: select count(*) from sqlite_master;
Android - Video Image is cut from the right side in GLSurfaceView

Categories

HOME
oracle12c
hyperlink
deep-learning
ggplot2
apache-jena
static
mysql-workbench
pascal
cakephp-3.4
visual-studio-emulator
google-admin-sdk
title
supervisor
comsol
scrolltop
dimensional-modeling
android-7.0-nougat
wolframalpha
shortest-path
solrcloud
selinux
imageresizer
monit
dynamically-generated
jboss6.x
amazon-quicksight
has-and-belongs-to-many
fractions
exchangewebservices
alm
calculation
livelink
recurring-events
anki
android-sugarorm
code-snippets
android-maps-extensions
reactjs.net
installscript
lubridate
hivemq
alphabetical
playframework-2.1
xcode7.3
modernizr
amazon-ses
odroid
jvmti
escpos
microsoft-metro
signal-strength
show-hide
oim
configurationmanager
manova
amq
er-diagram
pdf-conversion
mach-o
pybrain
reachability
rmongo
visual-studio-2008-sp1
stripe-connect
spring-cloud-feign
resourcemanager
ng-grid
avspeechsynthesizer
udpclient
lz77
libav
highland.js
atan2
xenomai
morton-number
nutiteq
kubuntu
rrule
ghcjs
linkedin-jsapi
gii
template-deduction
gnumeric
file-not-found
drupal-nodes
multitasking
eclipse-kepler
asdf
nevron
facebook-timeline
joomla-template
pstack
subproject
cgimage
virtualpathprovider
gobject-introspection
entity-attribute-value
cgbitmapcontextcreate
umra
dataform
luajava
aspmenu
folding
opml
sifr
blind

Resources

Mobile Apps Dev
Database Users
javascript
java
csharp
php
android
MS Developer
developer works
python
ios
c
html
jquery
RDBMS discuss
Cloud Virtualization
Database Dev&Adm
javascript
java
csharp
php
python
android
jquery
ruby
ios
html
Mobile App
Mobile App
Mobile App