微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

【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时输入中文字符,结束后恢复原来的键盘状态。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐