Quick Setting through UIAutomator

一个人想着一个人 提交于 2020-01-16 00:45:54

问题


I am trying to access one of the item in "Quick Settings" through uiautomator. I am able to open the quick setting through device.openQuickSettings(); After this, I am unable to get to a particular item for example WiFi / Airplane mode. Could some body help me to select an item in this quick settings?

I tried the following

if (new UiObject(new UiSelector().text("BRIGHTNESS")).exists())
{
    new UiObject(new UiSelector().text("BRIGHTNESS")).click();
}

and

if (new UiObject(new uiSelector().className("android.widget.GridView").description("AEROPLANE MODE")).exists())
{
    new UiObject(new UiSelector().className("android.widget.GridView").description("AEROPLANE MODE")).click();
}

But no success..

Thanks


I am to access the items using following

UiScrollable scroll = new UiScrollable(new UiSelector().scrollable(true));
UiObject airplane = scroll.getChildByText(new UiSelector().className(android.widget.TextView.class.getName()), "Aeroplane mode");

But, could anybody help me how to decide in uiautomator on Aeroplane mode is set or not in this Quick Settings menu?


回答1:


Did you get these texts - BRIGHTNESS , AEROPLANE MODE from uiautomatorviewer?

Check screenshot here of uiautomatorviewer from my Nexus 4 device -

Here it clearly shows 'Brightness' not 'BRIGHTNESS' so it should be used like :

new UiObject(new UiSelector().text("Brightness")).click();

Same goes for 'airplane mode' as well -

new UiObject(new UiSelector().text("Airplane mode")).click();

For check - you can do one thing -

Notice that when 'Airplane Mode' is ON -> wifi shows 'WI-FI OFF' and when 'Airplane Mode' is OFF -> wifi shows just 'WI-FI'

So you can do this -

//put airplane mode ON
new UiObject(new UiSelector().text("Airplane mode")).click();

//add some delay
sleep(3000);    //3sec delay

//check for wifi text
if(new UiObject(new UiSelector().text("Wi-Fi Off")).exists()) {
    System.out.println("Airplane Mode ON");
} else {
    System.out.println("Airplane Mode OFF");
}

Same you can check when airplane mode is put OFF.



来源:https://stackoverflow.com/questions/22681980/quick-setting-through-uiautomator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!