Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/213.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何在uiautomator中检测headsup通知?_Android_Notifications_Android Notifications_Android Uiautomator_Heads Up Notifications - Fatal编程技术网

Android 如何在uiautomator中检测headsup通知?

Android 如何在uiautomator中检测headsup通知?,android,notifications,android-notifications,android-uiautomator,heads-up-notifications,Android,Notifications,Android Notifications,Android Uiautomator,Heads Up Notifications,我正在使用Nexus 5和Cynagen One plus设备以及棒棒糖android操作系统。我正在尝试测试某些应用程序的各种通知。我成功地使用UiAutomator测试了托盘通知和锁屏通知,但我无法成功地使用headsup通知。我尝试了以下代码,但它没有检测到它 public void test_HeadsupTitle() throws InterruptedException, UiObjectNotFoundException, IOException { //some

我正在使用Nexus 5和Cynagen One plus设备以及棒棒糖android操作系统。我正在尝试测试某些应用程序的各种通知。我成功地使用UiAutomator测试了托盘通知和锁屏通知,但我无法成功地使用headsup通知。我尝试了以下代码,但它没有检测到它

    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中的headsup通知检测为要查找的对象

通过UiDevice中的滑动方法模拟滑动操作,并通过UiDevice从状态栏向下滑动。滑动(开始、开始、结束、结束、步骤)

@Before
public void setUp() throws Exception
{
    super.setUp();
    injectInstrumentation(InstrumentationRegistry.getInstrumentation());
    mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation());
}


@Test
public 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")
        .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();
}

出于好奇,您是如何测试托盘通知和锁屏通知的?我现在也需要这样做…在API 25上,scroller被识别为
android.widget.ScrollView
而不是
android.view.ViewGroup
虽然ScrollView是从ViewGroup派生的,但该检查失败。要修复此问题,只需删除
className
选择器,然后离开
packageName
res-id
(实际上只要res-id就足够了)这实际测试了什么?似乎在Android操作系统中测试代码,而不是自定义应用程序代码,因为它不会打开自定义应用程序使用的通知。如何为我的自定义应用创建通知?
/**
         * Open the notification bar with gestures
         * @throws UiObjectNotFoundException
         */
        public void testViewNotification() throws UiObjectNotFoundException{
                
                device.pressHome();
                
                device.swipe(300, 0, 300, 800, 50);
                device.waitForIdle(2000);
                device.pressBack();
                
        }