hopia
hopia

Reputation: 5006

How to close the Quick Settings system panel using UIAutomator?

In my android test, I have opened the quick settings panel using the following code:

device = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
device.openQuickSettings()

How do I now close or slide back the quick settings panel?

Upvotes: 4

Views: 845

Answers (1)

DntKnwHow2Code
DntKnwHow2Code

Reputation: 114

Even though there is no method to explicitly close it, you can use UiDevice object to call pressBack() method, on API >= 16. This Simulates a short press on the BACK button (The hardware back button on the device) to close the quick settings. With some devices, two pressBack()call is required. Example:

//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()

Upvotes: 3

Related Questions