显示断言 iOS 元素时有哪些最佳实践? [英] What Are Some Best Practices When Asserting iOS Elements Are Displayed?

查看:31
本文介绍了显示断言 iOS 元素时有哪些最佳实践?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Appium/Python 为 iOS 应用编写我的第一个 UI 自动化测试.

I'm trying to write my first UI Automation test for an iOS app with Appium/Python.

我发现当我列出 10 个像下面这样的断言时,我得到的结果非常不一致……有时它通过了,但通常第三个断言失败,有时第八个断言失败.

I find that when I list 10 assertions like the one below, I get very inconsistent results ... sometimes it passes, but it usually fails the third assertion, sometimes it fails the eighth.

assert driver.find_element_by_name('Settings').is_displayed()

我也尝试过使用等待:

driver.wait_for_element_by_name_to_display('Settings')
assert driver.find_element_by_name('Settings').is_displayed()

有没有人知道关于这个问题的任何好的资源?有什么提示或建议吗?

Does anyone know of any good resources on this issue? Any tips or advice?

推荐答案

有一个很好的 util 类可以用于这个 EC.这是 git 文档的链接

There is a good util class that can be used for this EC. Hereès the link to the git documentation

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

然后你可以用这种方式来检测一个元素是否存在:

Then you can use it this way to detect if an element is present:

from appium.webdriver.common.mobileby import MobileBy
# time in seconds
timeout = 10
wait = WebDriverWait(driver, timeout)
wait.until(EC.presence_of_element_located((MobileBy.NAME, 'Settings'))

如果您需要检测当前和可见的使用:

If you need to detect present and visible use:

wait.until(EC.visibility_of_any_elements_located((MobileBy.NAME, 'Settings'))

这篇关于显示断言 iOS 元素时有哪些最佳实践?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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