gpt4 book ai didi

android - 设备屏幕休眠时测试失败

转载 作者:搜寻专家 更新时间:2023-11-01 07:56:10 24 4
gpt4 key购买 nike

我正在尝试在 Android 设备上运行一些 Calabash 测试。如果我在运行测试之前手动转动屏幕,那么一切正常。在 Nexus 4 上,如果我关闭屏幕并尝试运行测试,那么我的第一个场景会在等待元素出现时超时。在 Galaxy Nexus 上,如果我在屏幕关闭的情况下开始测试,Calabash 会唤醒设备并通过测试。

是否有一些 Calabash 根本无法唤醒的设备? Nexus 4 是其中之一吗?手动打开设备是不可行的,因为我会在许多设备上频繁运行这些测试。

我发现了一些关于这个问题的过时引用。 Adam Niedzielski 于 2012 年在 https://groups.google.com/forum/#!topic/calabash-android/o6lUuEOuGtE 发表的一篇文章建议在 app_life_cycle_hooks.rb

中使用以下钩子(Hook)
include Calabash::Android::Operations

AfterConfiguration do |config|
wake_up
end

但代码已添加到 Calabash 中的 ruby-gem/bin/calabash-android 中,明确禁止包含 Operations 模块:https://github.com/calabash/calabash-android/commit/995daef9b6636e7e4e572aeb5d4f90d6d072320f所以我想这不再是推荐的方法。如果我删除 include 并只键入 Calabash::Android::Operations.wake_up,我会得到一个 NameError

最佳答案

我偶尔会遇到这个错误,最终将屏幕超时设置为超过一分钟并在开始测试之前运行此方法:

  def self.turn_on_screen(device_serial_number)
# Switches on the android devices screen if it isn’t already on.
if `adb -s #{device_serial_number} shell dumpsys input_method | grep mScreenOn`.include? 'false'
`adb -s #{device_serial_number} shell input keyevent KEYCODE_POWER`
end
end

如果屏幕尚未打开,这将模拟按下电源按钮。我已经在大约 4 种不同的设备上使用过它,到目前为止没有遇到任何问题,所以希望它对你有用。

可能值得注意的是,我还关闭了设备的锁屏。

编辑:更新 Lollipop 后,我不得不添加另一张支票。在我的所有测试设备上同时使用两者似乎都可以解决问题。

if `adb shell dumpsys input_method | grep mInteractive`.include? 'false'
`adb shell input keyevent KEYCODE_POWER`
end

关于android - 设备屏幕休眠时测试失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27322366/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com