我正在編寫用於在模擬器中運行Android應用程序的uiautomator測試用例。問題在於,假設我在不同的仿真器中運行Ui測試用例。我如何確保錄製機器和播放機器以相同的速度作出反應。例如,回放機器可能會比記錄機器反應慢。因此,當測試用例在按鈕中觸發點擊操作時,回放機器可能尚未在佈局中加載該按鈕。 uiautomator中是否有任何機制可以始終使測試用例的播放和機器響應同步?我擔心如果播放機速度太慢,那麼可能會拋出一些無法理解的異常。UiAutomator的同步
1
A
回答
3
通常,您可以使用UiDevice.wait(..)之類的功能暫停,直到您的測試可以繼續。例如,如果您有一個按鈕打開包含要與之交互的某些元素的屏幕,則在嘗試與這些元素進行交互之前,您需要等待新內容出現。
這看起來是這樣的:如果你知道點擊後會發生什麼
detailsButton.click();
device.wait(Until.hasObject(By.desc("Details Pane")), TIMEOUT);
// Do something on the details pane
0
艾倫發答案的作品就好了。如果不這樣做(如在我的情況),您可以:
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.
我因爲多次做這個的
device.waitForWindowUpdate(packageName, timeOut)
頂部等待將返回並在屏幕的根節點可能尚未被訪問,導致將來出現UiObjectNotFoundException。
相關問題
- 1. UIautomator的GUI
- 2. UiAutomator getLastTraversedText()
- 3. Android電視的Uiautomator
- 4. 在UiAutomator 2.0
- 5. Android UiAutomator測試
- 6. Uiautomator「am start」
- 7. UIAutomator與Android timepicker
- 8. 類不uiautomator
- 9. 同步不同步
- 10. 同步不同步
- 11. 如何中止uiautomator
- 12. 用UIAutomator測試android
- 13. UIAutomator/Espresso中的參數化
- 14. UiAutomator上的最新應用
- 15. Android UiAutomator - 檢測應用程序是否在uiautomator模式下
- 16. UiAutomator:如何使用uiautomator實現粘貼操作?
- 17. 同步塊內同步塊
- 18. 同步,同步內容流
- 19. 同步同步列表
- 20. 同步(這)與同步(MyClass.class)
- 21. 同步線程中的同步問題
- 22. 同步和java中的同步塊
- 23. 如何同步未同步的提交?
- 24. 使用同步塊的同步隊列
- 25. 的Android異步同步化
- 26. Node.js的異步/同步
- 27. jPanel的同步
- 28. 同步的XMLHttpRequest
- 29. HashMap的同步
- 30. 同步ICollection的
非常感謝。這幫助我嘗試調用虛擬方法'void android.support.test.uiautomator.UiObject2。'在一個空對象引用錯誤!因爲Uiautomator在下一個屏幕加載前退出 – gorbysbm
即使等待成功,它也會給我NPE。出於某種原因,「AccessibilityNodeInfo」中只有空的子元素,因此無法找到我的按鈕。看起來像一些錯誤。 – WindRider