参数化后
@pytest.mark.parametrize('searchkey, type, expect_price', [
('alibab', 'BABA', '180'),
('xiaomi', '01810', '180')
def test_search(self, searchkey, type, expect_price):
self.driver.find_element(AppiumBy.ID, 'com.xueqiu.android:id/tv_search').click()
self.driver.find_element(AppiumBy.ID, 'com.xueqiu.android:id/search_imput_text').send_keys(searchkey)
self.driver.find_element(AppiumBy.ID, 'com.xueqiu.android:id/name').click()
price_element = self.driver.find_element(AppiumBy.XPATH,
f"//*[@text='{type}']/../..//*[@resource-id='com.xueqiu']").send_keys(searchkey)
current_price = float(price_element.text)
assert_that(current_price, close_to(expect_price, expect_price * 0.2))
参数化前
from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy
"platformName": "Android",
"deviceName": "127.0.0.1:7555",
"appPackage": "com.xueqiu.android",
"appActivity": ".view.WelcomeActivityAlias",
"dontStopAppOnReset": True,
"skipDeviceInitialization": True
self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)
self.driver.implicitly_wait(10)
def test_search_ali(self):
self.driver.find_element(AppiumBy.ID, 'com.xueqiu.android:id/tv_search').click()
self.driver.find_element(AppiumBy.ID, 'com.xueqiu.android:id/search_imput_text').send_keys("alibab")
self.driver.find_element(AppiumBy.ID, 'com.xueqiu.android:id/name').click()
current_price = self.driver.find_element(AppiumBy.XPATH,
"//*[@text='BABA']/../..//*[@resource-id='com.xueqiu']").send_keys(
assert_that(current_price, close_to(expect_price, expect_price * 0.2))
def test_search_xiaomi(self):
self.driver.find_element(AppiumBy.ID, 'com.xueqiu.android:id/tv_search').click()
self.driver.find_element(AppiumBy.ID, 'com.xueqiu.android:id/search_imput_text').send_keys("alibab")
self.driver.find_element(AppiumBy.ID, 'com.xueqiu.android:id/name').click()
current_price = self.driver.find_element(AppiumBy.XPATH,
"//*[@text='BABA']/../..//*[@resource-id='com.xueqiu']").send_keys(
assert_that(current_price, close_to(expect_price, expect_price * 0.2))