I want to test application when battery is low. Is it possible to change battery level using Appium?
If you are running your test case locally, you can call adb. The following two commands can be used to change the battery level and update the rest of the system:
adb shell am broadcast -a android.intent.action.BATTERY_CHANGED --ei status 3 --ei level <desired_level> --ei scale 100
adb shell am broadcast -a android.intent.action.BATTERY_LOW
Thanks for your reply.
Is there a method to do this inside my test class on Eclipse or can we use just command prompt for this purpose?
As far as I know, this is not built into Appium. You will need to either explore appium-adb or make a system call from your test code.
Hi ,
i have a question on this issue , i need to change the battery charging state to discharging in the Intent.ACTION_BATTERY_CHANGE ( i need to run a test , that the phone is not charge but i use usb that charge the phone) , i try to use adb commands like "“adb shell am broadcast -a android.intent.action.BATTERY_CHANGED --ez present false --ei state 3 --ei level 40 --ei plugged 0” or “adb shell dumpsys battery set status 3 | set usb 0” but the intent isn’t change , can appium help with that or there is another way to handle this issue?
It may be due to the version of Android you are using. I’ve stopped working with Android recently, but I recall we were having problems with Android N or maybe O because of Android changes. As far as I know, Appium has nothing here to help you.