Android - application send to background while the tests are running

We are running our automated UI tests using Appium 1.6.0 and Cucumber JVM on our Jenkins machine (Mac OS X).
While the tests are running, for some reason, while the application is open, it is sent to background and therefore the remaining tests fail.

I was able to identify this behavior using ScreenShare and connecting to the machine remotely. I know I was the only one connected when this happened, so there is no chance that someone was messing with the emulator while the test was running.

I did go through the console log but couldn’t find any lead of why this would happen so I still couldn’t figure out a way of always reproducing this.

Any idea of what could cause this? Is there maybe a setting in the default emulator that could cause this?

Thank you.

first question: When it goes to background? On same step or randomly in different places?

Randomly in different places :(. Couldn’t find a pattern so far. And if I open it, it sends it back to background in a little while, and the tests are still running.

Is there maybe something in particular I should check through the console logs?

I figured out what the issues is.

It’s caused by the way our Cucumber feature files and scenarios are structured. Our scenarios are time - coupled, we intended for them to run in a given order, to mimic a flow - this is definitely bad design and we will need to refactor this.

The issue is that one of the scenarios fail and the one that follows taps the hardware back button and the application is closed.

So this is definitely not an Appium issue.

good you was found. without info about your app and exact test steps you are doing anyone hardly can suggest you something.

when you choose back button that send app into background you can always send it to foreground with:
try{driver.runAppInBackground(1) }catch(Exception e){}