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

  • 相关阅读:
    《人生七年》纪录片-个体心理学中的自卑与超越角度解读
    阿里云物联网平台之极速体验
    【Spring Cloud】Docker的基本操作
    嵌入式养成计划-51----ARM--ARM汇编指令--内存读写指令--程序状态寄存器传输指令--软中断指令--混合编程
    抖音商家找达人带货需要什么条件?达人带货靠谱吗
    NIO和多路复用
    Xcode中给UIView在xib中添加可视化的属性
    PostgreSQL索引篇 | BTree
    【NestJS系列】核心概念:Module模块
    Jenkins+Docker+SpringCloud微服务持续集成(下)
  • 原文地址:https://blog.csdn.net/qq_41904572/article/details/137250316