Open gingo opened 7 years ago
@gingo could you please add better description, looks like we are facing same problem
Please try to formulate question. What details do you need?
the second method is offline
How can be a method "offline"? Is it about internet state? How are you checking that internet is available? Are you waiting for some condition or checking only once?
Yes, networking is failing as mentioned in comment. There is probably some delay when calling this methods:
TestButler.setGsmState(true);
TestButler.setWifiState(true);
I guess, TestButtler should wait before wifi is in desired state and then return from this methods.
How are you checking that internet is available?
It takes some time for android OS to actually disable internet - so we are using something like this:
doEnable();
final ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
boolean result = PredicateWaiter.wait(RETRY_COUNT,
new PredicateWaiter.DelayDependOnCount.SimpleLinearDelay(PAUSE_MS),
new PredicateWaiter.Predicate() {
@Override
public boolean compute(int tryCount) {
NetworkInfo activeNetworkInfo = connectivityManager.getActiveNetworkInfo();
if (activeNetworkInfo == null) {
Log.d(TAG, "Predicate on " + tryCount + " is false because of activeNetworkInfo is null");
} else if (activeNetworkInfo.isAvailable()) {
Log.d(TAG, "Predicate on " + tryCount + " is false because of activeNetworkInfo.isAvailable() is false");
}
return activeNetworkInfo != null && activeNetworkInfo.isAvailable();
}
});
if (!result) {
throw new InternetManagerException("Internet was not enabled");
}
But sometimes internet do not coming back - even after 1 minute of waiting
I am having the same issue. The problem is that the test that disables the internet breaks down the following test although I am calling both setGsmState(true) and setWifiState(true) before the following tests. The only way to fix this for now is to test offline test in a separate test class.
I'm having the exact same problem as well. The first test will shutoff the wifi, and then re-enable it to do some network calls (which are successful). However the next test will have network calls time out.
I have made an Idling Resource to halt test until required connectivity state is met check it out here https://github.com/kushsaini10/connectivity-idling-resource
Hi there!
I have this two methods in my test-class:
Method
loadContentOffline()
is started first and even if internet connectivity is reenabled again the second method is offline. It works with Thread.sleep().