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

Ninepatch inconsistent for arrow button
Buttons not working with Surface view
OnCreate does not restore the bundle (null) in honeycomb
To display Soap Response (Array) in Android
How to change Android proximity sensor sensitivity?
What kind of Button can toggle/change states in Android?
How do you translate your Android app? [closed]
How do i pass Uri of image clicked in custom gallery to another activity?
Getting onActivityResult in Audio Intent
Android GPS false location retirieved
How do I change the phone number of an android emulator
With just one particular Bluetooth SPP module, .createRfcommSocketToServiceRecord() suddenly no longer works, but reflection method works
'Total Installs' in Android
Mobile version of Applications I need, to let App visible on Mobiles [closed]
ndk-build eclipse argument: not find class
How to stop freeze listView

Categories

HOME
gradient
javacc
newrelic
spring-data-mongodb
aws-cli
emscripten
web-hosting
barcode
discrete-mathematics
google-chrome-app
alamofire
angular-dart
radgridview
enterprise-architect
alpacajs
mathprog
vuejs
cfml
google-maps-autocomplete
springfox
ember-cli
roundup
xunit
perlbrew
pylons
asymptotic-complexity
comparable
alm
mobx
pdw-file-browser
lubridate
reason
ideascript
xdocreport
magento-1.9.3
plaintext
escpos
print-css
signal-strength
apache-spark-dataset
httr
optimizely
reportservice2010
vugen
google-cse
remedy
spring-data-couchbase
quicktime
lsyncd
flyout
testrail
microstation
latin
burrows-wheeler-transform
x-tag
simevents
qiime
cassia
deep
hadoop-partitioning
fuzzywuzzy
kendo-upload
decimalformat
microsoft-reporting
flock
ons-api
coda
ember-cli-rails
vacuum
pyobjc
cwrsync
cryptographichashfunction
infosphere-spl
webmatrix-3
beatsmusic
webfinger
trdion2011
unix-socket
dot42
websphere-esb
android-usb
eclipse-kepler
hibernate-entitymanager
ie8-compatibility-mode
isqlquery
alice
idn
intersect
pdfviewer
uimanageddocument
os.system
garbage
workflow-services
google-ajax-api
hbm2java
zend-rest
lobo-cobra

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