【python自动化测试】appium参数化用例

在实际测试过程中,有很多测试步骤一样但参数不同的情况。这种情况下,我们可以通过参数化实现编写一个测试,该测试用例可以完成所有相同步骤的测试。
参数化需要用到pytest的装饰器:@pytest.mark.parametrize()
参数化实例:

from appium import webdriver
from appium.webdriver.common.mobileby import MobileBy
from hamcrest import *
import pytest


class TestHamcrest:
    def setup(self):
        desire_cap = {
            "platformName": "Android",
            "deviceName": "mvq8aaw4ca5tcamn",
            "appActivity": ".view.WelcomeActivityAlias",
            "appPackage": "com.xueqiu.android",
            "skipServerInstallation": "true",
            "noReset": "true",
            "unicodeKeyBoard": "true",
            "resetKeyBoard": "true"
        }
        self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desire_cap)
        self.driver.implicitly_wait(10)

    def teardown(self):
        pass

    @pytest.mark.parametrize('searchkey,stockCode,expect_price', [
        ('千百度', '01028', 265),
        ('小米', '01810', 28)
    ])
    def test_param(self, searchkey, stockCode, expect_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.XPATH,
                                 '//*[@resource-id="com.xueqiu.android:id/listview"]/android.widget.RelativeLayout[1]').click()
        price = self.driver.find_element(MobileBy.XPATH,
                                                 f"//*[@text={stockCode}]/../../..//*[@resource-id='com.xueqiu.android:id/current_price']")
        current_price = float(price.text)
        print(current_price)
        print(current_price)
        print(current_price)
        assert_that(current_price, close_to(expect_price, expect_price * 0.1))
  • appium的配置中:
    •   "unicodeKeyBoard": "true",
        "resetKeyBoard": "true" 
      
    • 是为了能在send_key时输入中文字符,结束后恢复原来的键盘状态。
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值