Appium-Python-Client 升级变更

概述

appium框架应用以来,安卓端默认适配的Appium-Python-Client就是0.48版本,而最新版已经来到了2.7.1。期间经历了多个迭代,弃用、规范并重构了许多方法,Appium-Python-Client的更新势在必行。

说明

当前版本:0.48
最新版本:2.7.1

重要变更

1. TouchAction() 类和 MultiAction() 类 弃用 [链接]

自 v2.0.0版本起,弃用TouchAction() 类 和 MultiAction() 类 内的所有方法。

  • TouchAction() 类下的方法包括:
    • long_press()
    • move_to()
    • perform()
    • press()
    • release()
    • tap()
    • wait()
  • MultiAction() 类下的方法包括:
    • add()

之后,需要改用W3C标准 action来实现之前的功能:[链接]

from selenium.webdriver.common.action_chains import ActionChains

element = driver.find_element_by_accessibility_id("elId")
actions = ActionChains(driver)
actions.move_to_element(element)
actions.click(hidden_submenu)
actions.perform()

2. MobileBy() 类内方法移动到 AppiumBy() 类

image.png

3. 统一各类的 find_element_xx() 方法并移动到 AppiumBy() 类

自 v2.1.0版本起,AndroidSearchContext() 类内的所有方法 移动到 AppiumBy() 类。

Past Now
find_element_by_android_data_matcher() find_element(AppiumBy.ANDROID_DATA_MATCHER)
find_element_by_android_uiautomator() find_element(AppiumBy.ANDROID_UIAUTOMATOR)
find_element_by_android_view_matcher() find_element(AppiumBy.ANDROID_VIEW_MATCHER)
find_element_by_android_viewtag() find_element(AppiumBy.ANDROID_VIEWTAG)
find_elements_by_android_data_matcher() find_elements(AppiumBy.ANDROID_DATA_MATCHER)
find_elements_by_android_uiautomator() find_elements(AppiumBy.ANDROID_UIAUTOMATOR)
find_elements_by_android_viewtag() find_elements(AppiumBy.ANDROID_VIEWTAG)

自 v2.1.0版本起,CustomSearchContext() 类内的所有方法 移动到 AppiumBy() 类。

Past Now
find_element_by_custom() find_element(AppiumBy.CUSTOM)
find_elements_by_custom() find_elements(AppiumBy.CUSTOM)

自 v2.1.0版本起,iOSSearchContext() 类内的所有方法 移动到 AppiumBy() 类。

Past Now
find_element_by_ios_class_chain() find_element(AppiumBy.IOS_CLASS_CHAIN)
find_element_by_ios_predicate() find_element(AppiumBy.IOS_PREDICATE)
find_element_by_ios_uiautomation find_element(AppiumBy.IOS_UIAUTOMATION)
find_elements_by_ios_class_chain() find_elements(AppiumBy.IOS_CLASS_CHAIN)
find_elements_by_ios_predicate() find_elements(AppiumBy.IOS_PREDICATE)
find_elements_by_ios_uiautomation() find_elements(AppiumBy.IOS_UIAUTOMATION)

自 v2.1.0版本起,MobileSearchContext() 类内的所有方法 移动到 AppiumBy() 类。

Past Now
find_element_by_accessibility_id() find_element(AppiumBy.ACCESSIBILITY_ID)
find_elements_by_accessibility_id() find_elements(AppiumBy.ACCESSIBILITY_ID)

其中,该类内的 find_elements_by_image() 方法在 Appium 2.0中被删除,需要安装 「images」插件才能使用。

【已弃用】_class _WindowsSearchContext() 类
[Deprecated] Finds an element by windows uiautomation

  • find_element_by_windows_uiautomation()
  • find_elements_by_windows_uiautomation()

4. aunch_app()、close_app()、reset() 方法弃用

弃用原因:https://github.com/appium/appium/issues/15807
官方建议 后续借用 uninstall_app() 和 install_app() 两个方法来完成相关功能。
想来卸载重装的方案耗时过长,目前笔者的处理方法是:

# 使用adb命令清除app缓存,再唤起app
cmd = "adb shell pm clear " + app_pkg
os.system(cmd)
self.driver.activate_app(app_pkg)
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。
禁止转载,如需转载请通过简信或评论联系作者。

推荐阅读更多精彩内容