代码:
“”"
参数化用例
测试搜索功能,输入多个参数测试
“”"
import pytest
import time
from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
from hamcrest import *
class TestSearchFunc:
def setup(self):
desire_cap = {
“platformName”: “android”,
“deviceName”: “c02eda2b”,
“appPackage”: “com.xueqiu.android”,
“appActivity”: “.view.WelcomeActivityAlias”,
“noReset”: “true”,
“dontStopAppOnReset”: “true”,
“skipDeviceInitialization”: “true”
}
self.driver = webdriver.Remote(“http://127.0.0.1:4723/wd/hub”, desire_cap)
self.driver.implicitly_wait(10)
def teardown(self):
self.driver.find_element(MobileBy.ID, "com.xueqiu.android:id/action_close").click()
pass
@pytest.mark.parametrize('searchkey, stock_num, expected_price', [
('阿里巴巴', 'BABA', 210),
('小米', '01810', 25),
])
def test_search(self, searchkey, stock_num, expected_price):
self.driver.find_element(MobileBy.ID, "com.xueqiu.android:id/home_search").click()
self.driver.find_element(MobileBy.ID, "com.xueqiu.android:id/search_input_text").send_keys(searchkey)
self.driver.find_element(MobileBy.ID, "com.xueqiu.android:id/name").click()
#print(stock_num)
current_price = float(self.driver.find_element(MobileBy.XPATH, f"//*[@text='{stock_num}']/../../..//*[@resource-id='com.xueqiu.android:id/current_price']").text)
assert_that(current_price, close_to(expected_price, expected_price*0.1))
print(current_price)
报错信息:
raise exception_class(message, screen, stacktrace)
E selenium.common.exceptions.NoSuchElementException: Message: An element could not be located on the page using the given search parameters.
app图片: