android – 如何在uiautomator中检测抬头通知?

android – 如何在uiautomator中检测抬头通知?,第1张

概述我正在使用Nexus 5和Cyanogen One plus设备与Lollipop Android *** 作系统.我正在尝试测试某些应用的各种通知.我成功地能够使用UiAutomator测试托盘通知和锁定屏幕通知,但我无法通过抬头通知获得任何成功.我尝试了以下代码,但未能检测到它. public void test_HeadsupTitle() throws InterruptedException, 我正在使用Nexus 5和Cyanogen One plus设备与Lollipop Android *** 作系统.我正在尝试测试某些应用的各种通知.我成功地能够使用Uiautomator测试托盘通知和锁定屏幕通知,但我无法通过抬头通知获得任何成功.我尝试了以下代码,但未能检测到它.

public voID test_headsupTitle() throws InterruptedException,UiObjectNotFoundException,IOException{    //some code to bring up headsup notification    UiObject maxheadsUp = new UiObject(new UiSelector().packagename("com.androID.systemUI").resourceID("androID:ID/status_bar_latest_event_content"));    // code to add sleep so that it waits for heads up notification to show up    assertTrue(maxheadsUp.exists());}

有没有办法在Uiautomator中检测抬头通知作为运行自动化时要查找的对象?

解决方法
@Beforepublic voID setUp() throws Exception{    super.setUp();    injectInstrumentation(InstrumentationRegistry.getInstrumentation());    mDevice = UIDevice.getInstance(InstrumentationRegistry.getInstrumentation());}@Testpublic voID testNoti() throws UiObjectNotFoundException{    mDevice.openNotification();    mDevice.wait(Until.hasObject(By.pkg("com.androID.systemUI")),10000);    /*     * access Notification Center through resource ID,package name,class name.     * if you want to check resource ID,package name or class name of the specific vIEw     * in the screen,run 'uiautomatorvIEwer' from command.     */    UiSelector notificationStackScroller = new UiSelector()        .packagename("com.androID.systemUI")        .classname("androID.vIEw.VIEwGroup")        .resourceID("com.androID.systemUI:ID/notification_stack_scroller");    UiObject notificationStackScrollerUiObject = mDevice.findobject(notificationStackScroller);    assertTrue(notificationStackScrollerUiObject.exists());    /*     * access top notification in the center through parent     */    UiObject notiSelectorUiObject = notificationStackScrollerUiObject.getChild(new UiSelector().index(0));    assertTrue(notiSelectorUiObject.exists());    notiSelectorUiObject.click();}
总结

以上是内存溢出为你收集整理的android – 如何在uiautomator中检测抬头通知?全部内容,希望文章能够帮你解决android – 如何在uiautomator中检测抬头通知?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1127759.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存