UiAutomator的同步 [英] The synchronization of UiAutomator

查看:114
本文介绍了UiAutomator的同步的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写用于在模拟器中运行Android应用程序的uiautomator测试用例.假设我在另一台仿真器计算机上运行Ui测试用例,就会出现问题.如何确保记录机和播放机以相同的速度反应.例如,播放机的反应可能比记录机慢,因此,当测试用例触发按钮中的单击动作时,播放机可能尚未在布局中加载该按钮.uiautomator中是否有任何机制可以始终同步测试用例的播放和机器的反应?恐怕如果播放机速度太慢,那么可能会抛出一些未发现的异常.

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 could I ensure the record machine and the playback machine react in the same speed. For instance, the playback machine may react slower than the record machine, So when the test case triggers a click action in a button, the playback machine may not have loaded that button in the layout. Is there any mechanism in uiautomator which could always synchronize the playing of the test cases and the machine reaction? I am afraid if the playback machine is too slow, then some unfound exception may be thrown out.

推荐答案

通常,您使用类似

Generally you use functions like UiDevice.wait(..) to pause until your test can proceed.

例如,如果您有一个按钮可以打开一个包含要与之交互的元素的屏幕,则在尝试与这些元素进行交互之前,您需要等待新内容出现.

For example, if you have a button which opens a screen containing some elements you want to interact with, you'll need to wait for the new content to appear before trying to interact with those elements.

这看起来像:

detailsButton.click();

device.wait(Until.hasObject(By.desc("Details Pane")), TIMEOUT);

// Do something on the details pane

这篇关于UiAutomator的同步的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆