java - 如何使用 UIAutomator 关闭快速设置系统面板?
问题描述
在我的 android 测试中,我使用以下代码打开了快速设置面板:
device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
device.openQuickSettings()
我现在如何关闭或滑回快速设置面板?
解决方案
即使没有显式关闭它的方法,您也可以使用UiDevice
对象调用pressBack()
方法,API >= 16。这Simulates a short press on the BACK button
(设备上的硬件后退按钮)关闭快速设置。对于某些设备,pressBack()
需要两次调用。例子:
//Initialize UiDevice object
var uiDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
//Open Quick Settings
uiDevice.openQuickSettings()
//Close the quick settings
uiDevice.pressBack()
/*
* If you will be using this test on multiple devices
* and don't know if you need to pressBack() twice then,
* You can check for an object with the Description of "Airplane mode"
* Which would mean quickSettings still partly open, so press back button again
*
* var pressAgain = false
* for (uiObj in uiDevice.findObjects(By.descContains("Airplane mode")))
* pressAgain = true
*/
//Devices require 2 calls to pressBack()
//if(pressAgain)
// uiDevice.pressBack()
推荐阅读
- spotfire - 现场火分析师中的重叠日期
- javascript - CodeIgniter a.tag onclick if else 事件
- python - 如何建立自引用的多对多关系
- css - 如何在 Angular 应用程序的垫子抽屉组件中隐藏滚动条
- regex - 如果可选括号之间不存在任何内容,则不匹配
- json - 使用 Ansible 从 json 内容中获取特定的 dict 列表
- python - 用于在python中将rtf转换为文本的正则表达式
- javascript - 如何将 Javascript 数据连接/链接到 rails 方法?
- outlook - winappdriver,无法获取outlook预约窗口的页面源
- java - Spring Boot 内部化不适用于每个请求