• appium用例参数化


     参数化后

    1. @pytest.mark.parametrize('searchkey, type, expect_price', [
    2. ('alibab', 'BABA', '180'),
    3. ('xiaomi', '01810', '180')
    4. ])
    5. def test_search(self, searchkey, type, expect_price):
    6. self.driver.find_element(AppiumBy.ID, 'com.xueqiu.android:id/tv_search').click()
    7. self.driver.find_element(AppiumBy.ID, 'com.xueqiu.android:id/search_imput_text').send_keys(searchkey)
    8. self.driver.find_element(AppiumBy.ID, 'com.xueqiu.android:id/name').click()
    9. price_element = self.driver.find_element(AppiumBy.XPATH,
    10. f"//*[@text='{type}']/../..//*[@resource-id='com.xueqiu']").send_keys(searchkey)
    11. current_price = float(price_element.text)
    12. assert_that(current_price, close_to(expect_price, expect_price * 0.2))

     参数化前

    1. from appium import webdriver
    2. from appium.webdriver.common.appiumby import AppiumBy
    3. from hamcrest import *
    4. class TestAttr:
    5. def setup(self):
    6. desired_caps = {
    7. "platformName": "Android",
    8. "deviceName": "127.0.0.1:7555",
    9. "appPackage": "com.xueqiu.android",
    10. "appActivity": ".view.WelcomeActivityAlias",
    11. "noRest": "true", # 不清除缓存信息
    12. "dontStopAppOnReset": True, # 使用当前停留的页面进行元素操作,不会重新启动app加载页面
    13. "skipDeviceInitialization": True # 跳过安装权限设置等操作
    14. }
    15. self.driver = webdriver.Remote("http://127.0.0.1:4723/wd/hub", desired_caps)
    16. self.driver.implicitly_wait(10)
    17. def teardown(self):
    18. self.driver.back() # 返回到上一个页面
    19. self.driver.quit() # 退出driver
    20. def test_search_ali(self):
    21. self.driver.find_element(AppiumBy.ID, 'com.xueqiu.android:id/tv_search').click()
    22. self.driver.find_element(AppiumBy.ID, 'com.xueqiu.android:id/search_imput_text').send_keys("alibab")
    23. self.driver.find_element(AppiumBy.ID, 'com.xueqiu.android:id/name').click()
    24. current_price = self.driver.find_element(AppiumBy.XPATH,
    25. "//*[@text='BABA']/../..//*[@resource-id='com.xueqiu']").send_keys(
    26. "alibab")
    27. expect_price = 180
    28. assert_that(current_price, close_to(expect_price, expect_price * 0.2))
    29. def test_search_xiaomi(self):
    30. self.driver.find_element(AppiumBy.ID, 'com.xueqiu.android:id/tv_search').click()
    31. self.driver.find_element(AppiumBy.ID, 'com.xueqiu.android:id/search_imput_text').send_keys("alibab")
    32. self.driver.find_element(AppiumBy.ID, 'com.xueqiu.android:id/name').click()
    33. current_price = self.driver.find_element(AppiumBy.XPATH,
    34. "//*[@text='BABA']/../..//*[@resource-id='com.xueqiu']").send_keys(
    35. "alibab")
    36. expect_price = 180
    37. assert_that(current_price, close_to(expect_price, expect_price * 0.2))

  • 相关阅读:
    【看表情包学Linux】shell 命令及运行原理 | Linux 权限 | 文件权限的修改和转让 | 目录的权限 | Sticky bit 粘滞位
    AAOS CarPowerManager
    路径操作 合法路径名
    动态规划(AcWing): 1)计数类DP,2)树形DP,3)记忆化搜索,4)状态压缩DP,5)数位统计DP;
    云计算项目十:ES集群安装|部署kibana
    NPDP值得去学吗?
    MyCat的安装
    基于Java的教学评价管理系统设计与实现(源码+lw+部署文档+讲解等)
    L64.linux命令每日一练 -- 第十章 Linux网络管理命令 -- ifconfig和ifup
    企业如何通过CRM获得竞争力?
  • 原文地址:https://blog.csdn.net/qq_41904572/article/details/137250316