如何使用 UIAutomator 关闭快速设置系统面板?
How to close the Quick Settings system panel using 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()
在我的 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()