【问题标题】:Setting Date/Time from espresso adb shell android从 espresso adb shell android 设置日期/时间
【发布时间】:2018-10-03 11:12:38
【问题描述】:

我正在处理测试用例部分,我想检查即使在 android 设备内更改时间后我是否从服务器获得了正确的时间。为此,我使用 adb shell 命令覆盖日期和时间,但这并没有反映出来。

Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
int date1 = calendar.get(Calendar.DATE);
getInstrumentation().getUiAutomation().executeShellCommand("date -s 07171010.00");
getInstrumentation().getUiAutomation().executeShellCommand("am broadcast -a android.intent.action.TIME_SET");
calendar.setTimeInMillis(System.currentTimeMillis());
int date2 = calendar.get(Calendar.DATE);

【问题讨论】:

标签: android android-espresso


【解决方案1】:

根据我的经验,您必须在调用任何 ADB 命令后添加睡眠才能生效。
例如,请参阅此处的 cmets:https://stackoverflow.com/a/50859369/10472007 或者这里https://stackoverflow.com/a/37737047/10472007

引用最后一句:

该命令不会立即在设备上可见,因为它不会触发任何时间更改广播,但会在一分钟内可见。

看看吧!

根据 Alex P 给出的页面中的建议,根据您的设备/操作系统版本检查命令语法。

【讨论】:

    猜你喜欢
    • 2013-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-11-06
    • 1970-01-01
    • 1970-01-01
    • 2023-03-24
    • 1970-01-01
    相关资源
    最近更新 更多