Unresponsive Appium Server & Device Offline problems - android

Below are some common problem encountered when performing tests using Appium with Selenium - especially when running the tests for hours.
Some common Problems are:
sometimes midway into the tests, appium cannot connect to the Device. Logs say Device is offline (even though the device is online & app is accessible, manually)
sometimes midway into the tests, the chromedriver in the case of webview becomes unresponsive.
Questions:
Keeping the Device Constant - Is there a way to restart the Appium Server and connect it to the existing instance of the Android Device. This way i can resume tests where it abruptly stopped.
Keeping the Appium Server Constant - Is there a way to restart the APP on the Android Device and connect it to the existing instance of the Appium Server Session.
Is there some way to CHECK whether Appium Server and/or Android Device is offline / unresponsive ?

You can check whether device is offline w.r.t appium by hitting adb devices in the command prompt.
If it displays the device only then its online to appium server
If Server becomes unresponsive it might be an intermittent stale session issue. Better to stop and restart server from command prompt by hitting adb kill-server && sudo adb start-server

Few things can help you in minimising these issues drastically:
0. Put no lock and no screen saver on device.
1. Always start appium server before starting all tests, in case of testNG/junit framework, start in #BeforeClass or #BeforeTest method.
2. add this capabilities.setCapability("newCommandTimeout", "120") to appium driver, this will stop appium to timeout early thus avoiding nosessionfound exception etc.
3. assuming you are using appium v16 and latest chromedriver v20:
Problem: Chromedriver normally hangs while switching to and from webview but appium waits for chromedriver to respond until defined timeout and if it doesn't respond, appium gets timeout and then you may see hell lot of new issues like device not online, unknown error etc.
Solution: You can keep monitoring chromedriver, when it stops responding, you can start it programmatically, this way your test will get going.
Readymade solution: Download chromedriverhandler.jar from
1. https://github.com/mi2pankaj/chromeDriverHandler, add to your project,
2. use this in beforeTest/beforeClass or at the start of your test: ChromedriverHandler.chromeDriverHandlerThread().start();
3. use this in afterTest/afterClass or at the end of your test: ChromedriverHandler.chromeDriverHandlerThread().stop();
Hope this helps!!

Related

How to keep Android tests running even if the cable is disconnected?

I want to run Android tests for my App even if the cable is disconnected from machine.
Scenario:
I start Android tests from Android studio.
The tests take long time to finish.
The cable sometimes get disconnected (for many reasons) then the tests break.
I have to reset test data
Repeat from the beginning
However, I want my tests to keep running until they finish all test cases regardless of being connected to Android Studio.
I'm assuming the question is more about running tests on physical device. If that's the case, you may want to consider adb over tcp: https://developer.android.com/studio/command-line/adb#wireless however you will end up with another problem: your device will need to be charged from time to time, which basically means plugging your device anyways. Thus I'd suggest using Firebase test lab if that's an option: https://firebase.google.com/docs/test-lab. Last time I was checking, there was free tier for that.

Update user location to server when application is in background

Mobile Technology: React native
Live Tracking using: Socket.io
I have taxi services application, in which I'm updating driver's location continuously to server. It is working fine when application is foreground. Now I want to update location of driver to server using socket on any other way when the application is in background. I need solution that works for both ios/android.
Please share your suggestions
im not sure about using socket but you can try saving your data on an sqlite database then using react-native-background-task for when your app is in the background
https://github.com/jamesisaac/react-native-background-task
use it like so:
BackgroundTask.define(() => {
//API CALL
BackgroundTask.finish()
})
componentDidMount() {
BackgroundTask.schedule();
}
please note that it takes ATLEAST 15 minutes for it to be called on iOS
OK, here goes not such an answer more an explanation of the situation you are in.
I've been in the same situation before and there are some things you can do to test your React Native app in the same scenario as being in 'Doze Mode'. Android introduced this as a way to limit CPU and battery usage whilst the phone is in Doze Mode. Doze mode itself is reached if the phone is stationary and/or hasn't had any interaction with the user for a set amount of time.
Firstly, with your current solution - you want to test your app in Standby/Doze Mode. You can achieve this by doing the below:
Testing your app with Doze
You can test Doze mode by following these steps:
https://developer.android.com/training/monitoring-device-state/doze-standby#testing_doze
Configure a hardware device or virtual device with an Android 6.0 (API level 23) or higher system image.
Connect the device to your development machine and install your app.
Run your app and leave it active.
Force the system into idle mode by running the following command:
$ adb shell dumpsys deviceidle force-idle
When ready, exit idle mode by running the following command:
$ adb shell dumpsys deviceidle unforce
Reactivate the device by performing the following command:
$ adb shell dumpsys battery reset
Observe the behavior of your app after you reactivate the device. Make sure the app recovers gracefully when the device exits Doze.
This will give you your testing scenario in order to test on Android.
The problem:
Android gives the apps less and less control of phones connectivity whilst in the background. It will stop networking all together and only opens in a 'Maintenance Window'. Android state:
The Doze restriction on network access is also likely to affect your app, especially if the app relies on real-time messages such as tickles or notifications. If your app requires a persistent connection to the network to receive messages, you should use Firebase Cloud Messaging (FCM) if possible.
The issue:
The problem is not running your app in the background, your problem will be using network in the background. For example, headless JS will run - runnable tasks will run BUT it may not be able to make any requests for network.
Possible solutions:
Using Alarms
If you need to set alarms that fire while in Doze, use setAndAllowWhileIdle() or setExactAndAllowWhileIdle().
Alarms set with setAlarmClock()continue to fire normally — the system exits Doze shortly before those alarms fire.
Putting your App into a whitelist (visit the link above for acceptable use cases).
iOS:
For React Native, I used this:
https://github.com/mauron85/react-native-background-geolocation
This also works for Android, however the Doze mode (in my case) wouldn't send off network requests.

Missing network param from emulator

I try to change the network type from android emulator. From the official android documentation (https://developer.android.com/studio/run/emulator-commandline.html), i want to use network to change LTE/UMTS/GPRS network type. I create a new emulator from the last Android Studio 2.2 and connect with telnet. I run the help command (after authentication) and I get :
Android console command help:
help|h|? print a list of commands
crash crash the emulator instance
kill kill the emulator instance
quit|exit quit control session
redir manage port redirections
power power related commands
event simulate hardware events
avd control virtual device execution
finger manage emulator fingerprint
geo Geo-location commands
sms SMS related commands
cdma CDMA related commands
gsm GSM related commands
rotate rotate the screen by 90 degrees
I don't see network as explain in the documentation and when I try to run a network command, I get an error... Anybody have already met this issue ? Any idea how to solve it ?
Ok, seems to be delete in last versions of the emulator. I hope the android team will implement this feature soon.
https://code.google.com/p/android/issues/detail?can=2&start=0&num=100&q=emulator%20network%20unknown&colspec=ID%20Status%20Priority%20Owner%20Summary%20Stars%20Reporter%20Opened&groupby=&sort=-id%20-stars&id=204888

NodeJS script on Azure VM

I've setup a Linux VM on Azure which has NodeJS and MongoDB installed.
Then I have a single node script that I need to be constantly running (it receives and sends Google push notifications generated from an Android app and saves to my MongoDB accordingly).
So far the only way I can get it to run is by connecting via ssh on my local machine, running the script with "node gcm.js", which works fine. But when I disconnect from the server the script stops running... So how do I run it without needing to connect with my local machine? A cron job that starts just one time? Or have I gone about this in completely the wrong way?
Per my experience, there is a simple way for keeping the current process running as a background job.
Here is the steps below.
Connecting via ssh on local machine, then running the script node gcm.js.
Enter Ctrl+Z for stoping the current process, then you will see below, the N number of the [N]+ below is the job id.
^Z
[N]+ Stopped node gcm.js
Enter bg %N to convert the N job from a stoped foregroud job into a background job.
Enter disown -h %N to remove the N job from the job list of the current shell, then the process will be running after closing the current ssh connection.
More details for these linux commands, I think you can easily get via search engine.
Hope it helps.

Android TV SDK : Setting Proxy for the Emulator?

I have installed the Android TV SDK Developer preview for Windows. I am in a corporate intranet environment. I can start the Emulator, but the main screen endlessly loops with the "Preparing Recommendations" animation. I can navigate to the Settings and see that there is no network (no wired and no ethernet).
I suspect this might be a proxy issue. I have tried launching the Emulator with the following command:
C:\Eclipse_w_Android\adt-bundle-windows-x86-20140624\sdk\tools>emulator -avd AVD_for_Android_TV_1080p_by_Google_X86 -http-proxy http://MY_PROXY_IP:8080
(MY_PROXY_IP is replaced with my company's IP address)
It launches the Emulator but doesn't seem to have any effect on the network.
Has anyone else been able to get the Android TV Emulator to fully load in a heavily firewalled / proxied environment?
I thought I was experiencing this issue as well (and had originally commented as such), but I later realized that there was no actually connectivity problem. Two things to note:
"Preparing Recommendations" will appear indefinitely, and I presume this is simply because there are no apps by default feeding recommendations to populate this screen.
Both the Ethernet and Wireless items will show that they are not connected. However, if you run an app that uses the network (a simple WebView is sufficient as long as the app has INTERNET permissions), you'll see that it connects just fine.
I would suggest trying a test app to check connectivity, as there is no other indicator I can find suggesting that it is working properly. I suspect you'll find that all is well.
you probably forgot the first part username password # server port
your company probably has the ip setup with username password

Categories

Resources