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))
相关推荐
OreoCC6 分钟前
第N5周:Pytorch文本分类入门
人工智能·pytorch·python
zimoyin2 小时前
解决 Java/Kotlin 资源加载问题
java·python·kotlin
wjcroom2 小时前
数字投屏叫号器-发射端python窗口定制
开发语言·python
静候光阴2 小时前
python使用venv命令创建虚拟环境(ubuntu22)
linux·开发语言·python
Y1nhl2 小时前
力扣hot100_二叉树(4)_python版本
开发语言·pytorch·python·算法·leetcode·机器学习
wjcroom3 小时前
文本转语音-音画适时推送rtsp并播放
python
老胖闲聊4 小时前
Flask 全栈学习指南
后端·python·flask
小枫小疯4 小时前
Pytorch 转向TFConv过程中的卷积转换
人工智能·pytorch·python
油盐不进的吗4 小时前
4.桥接模式
开发语言·python·桥接模式
魔障阿Q4 小时前
labelimg标注的xml标签转换为yolo格式标签
xml·人工智能·python·深度学习·yolo·计算机视觉