【发布时间】:2021-10-20 19:41:49
【问题描述】:
我需要你的专业知识.. 我正在尝试使用 Python、Appium 框架自动化一个简单的测试用例,我正面临这个问题,试图重构您的代码以使用页面对象模型方法。使用 Pytest 作为测试运行器。我在下面收到此错误,我是这些技术的新手,请帮助我破译这个谜。谢谢。
供参考,这个测试用例在重构之前成功通过,下面是代码片段:
def test_item_details_page(driver):
wait = WebDriverWait(driver, 10)
wait.until(EC.presence_of_element_located((MobileBy.XPATH, '//android.widget.TextView[@index=2]'))).click()
assert wait.until(EC.presence_of_element_located((MobileBy.XPATH, '//android.widget.TextView[@text="Item Facts"]'))).text == "Item Facts"
> raise TimeoutException(message, screen, stacktrace)
E selenium.common.exceptions.TimeoutException: Message:
/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/support/wait.py:80: TimeoutException
到目前为止,我的项目文件夹中有以下 3 个文件: conftest.py
import pytest
from os import path
from appium import webdriver
CUR_DIR = path.dirname(path.abspath(__file__))
APP = path.join(CUR_DIR, 'app.apk')
APPIUM = 'http://localhost:4723/wd/hub'
@pytest.fixture
def driver():
CAPS = {
'platformName': 'Android',
'platformVersion': '11.0',
'deviceName': 'Pixel 3',
'automationName': 'UIAutomator2',
'app': APP,
}
driver = webdriver.Remote(APPIUM, CAPS)
yield driver
driver.quit()
home_view.py
from selenium.webdriver.support import expected_conditions as EC
class HomeView(object):
GEM_ITEM = (MobileBy.XPATH, '//android.widget.TextView[@index=2]')
def __init__(self, driver):
self.driver = driver
def nav_to_details_page(self):
wait = WebDriverWait(self.driver, 10)
#self to access to the class variable
wait.until(EC.presence_of_element_located(self.GEM_ITEM)).click()
test_detail_page.py
from appium.webdriver.common.mobileby import MobileBy
from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from views.home_view import HomeView
def test_item_details_page(driver):
# instantiate the page object
home = HomeView(driver)
home.nav_to_details_page
wait = WebDriverWait(driver, 10)
assert wait.until(EC.presence_of_element_located((MobileBy.XPATH, '//android.widget.TextView[@text="Item Facts"]'))).text == "Item Facts"
【问题讨论】:
标签: android python-3.x appium pytest