appium用例参数化

 参数化后

@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
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))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值