fka*_*ng9 10 python ios appium
我正在测试一个原生iOS应用程序,需要等待一些元素加载我的一些测试.Appium现在在某些屏幕上运行得太快了.
有人可以指点一个使用WebDriverWait样式等待Appium iOS测试的例子吗?这里有一个问题可以回答:在使用Appium和Ruby测试iOS应用程序时,等待加载元素?.在Python中寻找类似的东西.
Python客户端文档似乎没有记录等待函数.
谢谢.
Cyn*_*nic 10
在测试的顶部导入这些.
from appium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
Run Code Online (Sandbox Code Playgroud)
TL/DR应该可以工作,你可能需要在wait =部分中将self.driver更改为只是驱动程序,具体取决于你的工作方式.此外,显然将By.XPath更改为您正在使用的任何定位器:
wait = WebDriverWait(self.driver, 20)
currently_waiting_for = wait.until(EC.element_to_be_clickable((By.XPATH,'//UIAApplication[1]/UIAWindow[1]/UIAButton[@text="example text"]')))
Run Code Online (Sandbox Code Playgroud)
或者您可以告诉驱动程序使用隐式等待.
self.driver.implicitly_wait(10)
myElement = driver.find_element_by_id("fakeid")
myElement.click()
Run Code Online (Sandbox Code Playgroud)
这是一个使用等待登录到Android应用程序的示例(没有在ios上使用它但它应该是类似的)使用默认帐户选择器然后断言正确的文本出现.在设置过程中,我正在从另一个文件加载我想要的功能.
class TrainUpSmokeTests(unittest.TestCase):
def setUp(self):
desired_caps = desired_capabilities.get_desired_capabilities('app-debug.apk')
self.driver = webdriver.Remote('http://localhost:4723/wd/hub', desired_caps)
def tearDown(self):
self.driver.quit()
def example_test(self):
wd = self.driver
## Depending on how you're running the test the first variable may just be driver. Or in my case self.driver which I shortened above. The number is how many seconds it should wait before timing out.
wait = WebDriverWait(wd, 20)
## Waiting for account selector to be clickable.
currently_waiting_for = wait.until(EC.element_to_be_clickable((By.XPATH,'//android.widget.CheckedTextView[@text="FakeEmail@example.com"]')))
## Locating test account and selecting it.
account = wd.find_element_by_android_uiautomator('text("FakeEmail@example.com")')
account.click()
ok_button = wd.find_element_by_android_uiautomator('text("OK")')
ok_button.click()
## Waiting for an Element on the home screen to be locatable.
currently_waiting_for = wait.until(EC.presence_of_element_located((By.XPATH,'//android.widget.RelativeLayout[@resource-id="com.name.app:id/overview"]')))
hero_headline = wd.find_element_by_android_uiautomator('new UiSelector().description("Example Header")')
self.assertIsNotNone(hero_headline)
if __name__ == '__main__':
suite = unittest.TestLoader().loadTestsFromTestCase(TrainUpSmokeTests)
unittest.TextTestRunner(verbosity=2).run(suite)
Run Code Online (Sandbox Code Playgroud)
这是一个使用appium(而不是应用程序)的网站测试.更改设置,以便self.driver打开浏览器.
self.driver = webdriver.Firefox()
Run Code Online (Sandbox Code Playgroud)
然后使用By选择器,如类,名称,id,例如下面的示例.
currently_waiting_for = wait.until(EC.element_to_be_clickable((By.CLASS_NAME,'search-results')))
Run Code Online (Sandbox Code Playgroud)
这篇文章也有帮助.此外,如果您不知道如何找到xpath,请查看设置appium附带的uiautomatorviewer.
您可以使用隐式等待。像remoteWebDriver.implicitlyWait(time, timeUnit)这样的东西当然是针对java的。python 应该也有类似的东西。
| 归档时间: |
|
| 查看次数: |
6189 次 |
| 最近记录: |