显示断言iOS元素时有哪些最佳实践? [英] What Are Some Best Practices When Asserting iOS Elements Are Displayed?
问题描述
我正在尝试使用Appium/Python为iOS应用编写我的第一个UI自动化测试.
I'm trying to write my first UI Automation test for an iOS app with Appium/Python.
我发现当我列出下面的10个断言时,我得到的结果非常不一致...有时它通过了,但是通常使第三个断言失败,有时使第8个断言失败.
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屋!