appium用例参数化

参数化后

python 复制代码
@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))

参数化前

python 复制代码
from appium import webdriver
from appium.webdriver.common.appiumby import AppiumBy
from hamcrest import *


class TestAttr:
    def setup(self):
        desired_caps = {
            "platformName": "Android",
            "deviceName": "127.0.0.1:7555",
            "appPackage": "com.xueqiu.android",
            "appActivity": ".view.WelcomeActivityAlias",
            "noRest": "true",  # 不清除缓存信息
            "dontStopAppOnReset": True,  # 使用当前停留的页面进行元素操作,不会重新启动app加载页面
            "skipDeviceInitialization": True  # 跳过安装权限设置等操作
        }

        self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)
        self.driver.implicitly_wait(10)

    def teardown(self):
        self.driver.back()  # 返回到上一个页面
        self.driver.quit()  # 退出driver

    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(
            "alibab")
        expect_price = 180
        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(
            "alibab")
        expect_price = 180
        assert_that(current_price, close_to(expect_price, expect_price * 0.2))
相关推荐
云泽野3 小时前
【Java|集合类】list遍历的6种方式
java·python·list
IMPYLH5 小时前
Python 的内置函数 reversed
笔记·python
小赖同学啊7 小时前
物联网数据安全区块链服务
开发语言·python·区块链
码荼7 小时前
学习开发之hashmap
java·python·学习·哈希算法·个人开发·小白学开发·不花钱不花时间crud
小陈phd8 小时前
李宏毅机器学习笔记——梯度下降法
人工智能·python·机器学习
kk爱闹8 小时前
【挑战14天学完python和pytorch】- day01
android·pytorch·python
Blossom.1188 小时前
机器学习在智能建筑中的应用:能源管理与环境优化
人工智能·python·深度学习·神经网络·机器学习·机器人·sklearn
亚力山大抵9 小时前
实验六-使用PyMySQL数据存储的Flask登录系统-实验七-集成Flask-SocketIO的实时通信系统
后端·python·flask
showyoui9 小时前
Python 闭包(Closure)实战总结
开发语言·python
amazinging9 小时前
北京-4年功能测试2年空窗-报培训班学测开-第四十一天
python·学习·appium