Android Espresso Test - Changing System Time Format -


in android app, there activity shows time string according system time format (12hr. / 24hr.). writing espresso test test behavior whether time displays gets changed system time format changes.

in order achieve this, want change system time format through instrumentation test pure testing purpose. , i've added permission in test project's manifest, this

<uses-permission android:name="android.permission.write_settings"/>

and wrote following code change system time format

context context = instrumentationregistry.getcontext(); settings.system.putstring(context.getcontentresolver(),settings.system.time_12_24, "12"); 

and throwing permission denial error. (you can use below link see stack trace)

error stacktrace screenshot

i not able understand, since code trying change system time format in test project , has permission change system time setting, verified using command adb shell dumpsys package com.my.app.package | grep permission

please tell me, missing here ?

i've found explanation issue. here it:

the user application not have permission change device time. please read answer cashbash in following post alternate option.

copying here quick reference:

according this thread, user apps cannot set time, regardless of permissions give it. instead, best approach make user set time manually. use:

startactivity(new intent(android.provider.settings.action_date_settings)); 

unfortunately, there no way link them directly time setting (which save them 1 more click). making use of ellapsedrealtime, can ensure user sets time correctly.

from: set android's date/time programmatically

try instead of using espresso, use uiatomator instrumentation test framework can perform actions dialogs, marshmallow permissions or lockscreen.

it works espresso. check site: http://qathread.blogspot.com/2015/05/espresso-uiautomator-perfect-tandem.html

hope help


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -