Skip to content

Latest commit

 

History

History
182 lines (150 loc) · 5.19 KB

2to3.md

File metadata and controls

182 lines (150 loc) · 5.19 KB

2.x到3.x升级说明

变更内容简介

  • 移除atx-agent,常驻服务移除,改为运行时启动手机内的uiautomator服务
  • 直接通过atx-agent地址连接的方法不再支持,connect函数目前只支持本地的USB设备或adb connect状态的设备
  • 环境变量 ANDROID_DEVICE_IP 不再支持,如果需要使用环境变量传递序列号可以使用 ANDROID_SERIAL
  • 版本管理从pbr改为poetry,同时降低依赖库的数量
  • Python依赖调整为最低3.8
  • 增加更多的单测
  • 日志使用标准库logging, 默认不输出任何内容,除非手动开启
  • minicap,minitouch不再默认安装
  • atx-agent[armeabi]直接打包到lib里面去,避免外网下载依赖

New

  • Add function enable_pretty_logging
  • Add class AdbShellError, HierarchyEmptyError, HTTPError
  • Add d.xpath.get_page_source() -> PageSource

Breaking changes (移除的功能)

Lib removes

  • Remove logzero
  • Remove filelocks
  • Remove progress
  • Remove packaging
  • Remove Pillow

Module removes

  • Remove module uiautomator2.ext.xpath

Class removes

  • Remove class AdbUI
  • Remove class GatewayError
  • Remove class ServerError, UiautomatorQuitError, RequestError, UiaError, JsonRpcError, NullObjectExceptionError, NullPointerExceptionError, StaleObjectExceptionError

Property removes

  • Remove property u2.logger
  • Remove property u2.xpath.XPath.logger
  • Remove property d.watcher.debug
  • Remove property: address, 原来是用于获取atx-agent的URL地址
  • Remove property: alive, 原来用于检测atx-agent的存活状态
  • Remove property: uiautomator, 原来用法是d.uiautomator.stop()
  • Remove property: widget, 原来也不怎么用
  • Remove property: http, 原来是这样用的d.http.get("/device_info")
  • Remove d.settings["xpath_debug"]

Function removes

  • Remove function current_app, use app_current instead
  • Remove function d.xpath.apply_watch_from_yaml
  • Remove function healcheck, 原来是未来恢复uiautomator服务用的
  • Remove function service(name: str) -> Service, 原本是用于做atx-agent的服务管理
  • Remove function app_icon() -> Image, 该函数依赖atx-agent
  • Remove function connect_wifi() -> Device, 该函数依赖atx-agent
  • Remove function connect_adb_wifi(str) -> Device, 直接用connect就行了
  • Remove function set_new_command_timeout(timeout: int), 用不着了
  • Remove function open_identify(), 打开一个比较明显的界面,这个函数出了点毛病,先下掉了

XPath (d.xpath) methods

  • remove dump_hierarchy
  • remove get_last_hierarchy
  • remove add_event_listener
  • remove send_click, send_longclick, send_swipe, send_text, take_screenshot
  • remove when, run_watchers, watch_background, watch_stop, watch_clear, sleep_watch
  • remove position method, usage like d.xpath(...).position(0.2, 0.2)

InputMethod

  • deprecated wait_fastinput_ime
  • deprecated set_fastinput_ime use set_input_ime instead

Command remove

  • Remove "uiautomator2 healthcheck"
  • Remove "uiautomator2 identify"

Function changes

connect_usb

  • 2.x connect_usb(serial, init: bool)
  • 3.x connect_usb(serial)

shell

  • 2.x shell(cmdargs, stream: bool, timeout)
  • 3.x shell(cmdargs, timeout)

push

  • 2.x push(src, dst, mode, show_process: bool)
  • 3.x push(src, dst, mode)

xpath

  • 2.x d.xpath("...").wait() -> XMLElement|None
  • 3.x d.xpath("...").wait() -> bool

reset_uiautomator

  • 2.x reset_uiautomator(self, reason="unknown", depth=0)
  • 3.x reset_uiautomator()

app_info

2.x Response

{
    "mainActivity": "com.github.uiautomator.MainActivity",
    "label": "ATX",
    "versionName": "1.1.7",
    "versionCode": 1001007,
    "size":1760809
}

3.x Response

{
    "versionName": "1.1.7",
    "versionCode": 1001007,
}

session

  • 2.x sess = d.session("com.netease.cloudmusic", attach=True, strict=True)
  • 3.x sess = d.session("com.netease.cloudmusic", attach=True)

It seems the strict is useless, so I delete it.

push

  • 2.x push(src, dst, mode, show_process:bool=False)
  • 3.x push(src, dst, mode)

device_info

print(d.device_info)

2.x prints

{'udid': '08a3d291-26:17:84:b6:cb:a0-DT1901A',
 'version': '10',
 'serial': '08a3d291',
 'brand': 'SMARTISAN',
 'model': 'DT1901A',
 'hwaddr': '26:17:84:b6:cb:a0',
 'sdk': 29,
 'agentVersion': '0.10.0',
 'display': {'width': 1080, 'height': 2340},
 'battery': {'acPowered': False,
  'usbPowered': True,
  'wirelessPowered': False,
  'status': 5,
  'health': 2,
  'present': True,
  'level': 100,
  'scale': 100,
  'voltage': 4356,
  'temperature': 292,
  'technology': 'Li-poly'},
 'memory': {'total': 7665272, 'around': '7 GB'},
 'cpu': {'cores': 8, 'hardware': 'Qualcomm Technologies, Inc SM8150'},
 'arch': '',
 'owner': None,
 'presenceChangedAt': '0001-01-01T00:00:00Z',
 'usingBeganAt': '0001-01-01T00:00:00Z',
 'product': None,
 'provider': None}

3.x prints

{'serial': 'VVY0223208008426',
'sdk': 31,
'brand': 'HUAWEI',
'model': 'JAD-AL80',
'arch': 'arm64-v8a',
'version': 12}

app_current

  • 2.x raise OSError if couldn't get focused app
  • 3.x raise DeviceError if couldn't get focused app

current_ime

  • 2.x return (ime_method_name, bool), e.g. ("com.github.uiautomator/.FastInputIME", True)
  • 3.x return ime_method_name, e.g. "com.github.uiautomator/.FastInputIME"