The synchronization of UiAutomator

后端 未结 2 1907
面向向阳花
面向向阳花 2021-01-14 23:55

I am writing uiautomator test case for running Android app program in emulator. Here comes the problem, assume I run the Ui test case in a different emulator machine. How co

2条回答
  •  感情败类
    2021-01-15 00:49

    Allen Hair answer works just fine if you know what to expect after the click. If you don't (like in my case) you can:

    UiAutomation uiAuto = InstrumentationRegistry.getIntrumentation().getUiAutomation(); //gets the UiAutomation for this execution
    AccessibilityNodeInfo rootNode = uiAuto.getRootInActiveWindow();  //gets the root node of the currently visible screen
    //makes sure there is a rootNode and that is has children, i.e., there is a drawn screen
    while(rootNode == null || rootNode.getChildCount() == 0){
        rootNode = uiAuto.getRootInActiveWindow();
    }
    //getting here you are sure that the new screen is drawn.
    

    I do this on top of

    device.waitForWindowUpdate(packageName, timeOut)
    

    because in several occasions the wait would return and the root node of the screen could not yet be accessed, resulting in future UiObjectNotFoundException.

提交回复
热议问题