2

I am currently working on test and I would like to simulate a poor connection while I am testing with espresso. Is there any way to fake this in code?

In my app when there is a call api, I launch animations and I just would like to ensure that with a poor connection this animation will be running until all the data are received.

I am looking for an in code solution, I am aware of some of the different workaround or use of the emulator, I am really looking for something in code.

adc
  • 76
  • 8

4 Answers4

5

You can set it in emulator settings, in Network section: enter image description here

Viktor Sinelnikov
  • 1,631
  • 2
  • 16
  • 26
0

A workaround for real device testing: If you have an iPhone, you can create an iPhone hotspot and use the iPhone bad network simulation.

bradkratky
  • 1,577
  • 1
  • 14
  • 28
0

Another way to simulate would be using something like charles, very nice if you don´t want or can´t use the simulator, it´s not the main purpose of the program (mainly for http testing) but can be used for that too.

I´m not sure but I thought Android 6.0 or Samsung (someone correct this statement plz) has it as an option in the developer settings themselves.

There also programs to lower you connection speed on the mac so you can use bluetooth to share your internet connection with the device, downside is the hole pc internet is slow while testing. And it´s not a very convenient.

0

Update 1 :

You can add delay in espresso by using

SystemClock.sleep(10000);

haven't tried it. Can you try and update here?


Update 2 :

http://droidtestlab.com/delay.html this link might be useful.


As suggested you should be able to emulate Network speed either by emulator or using something like charles. If you want to have an extended delay via code (I hope for testing purpose only, like you mentioned in your updated question) you can use Handler with runnable, just after your network request is over and before updating your views with that data.

Handler handler = new Handler(); 
handler.postDelayed(new Runnable() {
     @Override 
     public void run() { 

     } 
}, 10000); // 10sec delay 

and update your views inside the Runnable's run() function.

Kushal Sharma
  • 5,978
  • 5
  • 25
  • 41