Skip to main content

UI Automation Framework for Harmony Next

Project description

hmdriver2

在写这个项目前github上已有个hmdirver框架,但它是侵入式的(需要提前在手机端安装一个testRunner app)。另外鸿蒙官方提供的hypium自动化框架,使用复杂,依赖繁杂。于是决定重新写一套框架,解决上述两个框架的弊端。

hmdriver2是一款支持鸿蒙Next系统的UI自动化框架,无侵入式,提供应用管理,UI操作,元素定位等功能,轻量高效,上手简单,为你快速实现鸿蒙应用的自动化测试需求。

Feature

  • 支持鸿蒙Next系统的所有设备自动化
  • 无侵入式,无需在手机安装基于arkTS的testRunner APP
  • 支持应用管理(启动/停止/安装/卸载/获取应用列表等等)
  • 支持UI操作和元素定位(点击/滑动/输入/元素查找等等等)
  • 稳定高效,直接和鸿蒙底层uitest服务通过socket通信
  • 使用python语言编写测试用例,上手简单,即插即用

Install

pip3 install hmdirver2

Usage

from hmdriver2.driver import Driver
from hmdriver2.proto import KeyCode, DisplayRotation, ComponentData


# New driver
d = Driver("FMR0223C13000649")

# App management
d.start_app("com.kuaishou.hmapp", "EntryAbility")
d.stop_app("com.kuaishou.hmapp")
d.clear_app("com.kuaishou.hmapp")
d.install_app("~/develop/harmony_prj/demo.hap")

# KeyCode: https://docs.openharmony.cn/pages/v4.1/en/application-dev/reference/apis-input-kit/js-apis-keycode.md
d.go_back()
d.go_home()
d.press_key(KeyCode.POWER)
d.screen_on()
d.screen_off()
d.unlock()

# Device Info
# DeviceInfo(productName='HUAWEI Mate 60 Pro', model='ALN-AL00', sdkVersion='12', sysVersion='ALN-AL00 5.0.0.60(SP12DEVC00E61R4P9log)', cpuAbi='arm64-v8a', wlanIp='172.31.125.111', displaySize=(1260, 2720), displayRotation=<DisplayRotation.ROTATION_0: 0>)
d.device_info
d.display_size
d.display_rotation

# Execute HDC shell command
d.shell("ls -l")

# Open scheme
d.open_url("http://www.baidu.com")

# Push and pull files
d.pull_file(rpath, lpath)
d.push_file(lpath, rpath)

# Device Screenshot
d.screenshot(lpath)

# Device touch
d.click(500, 1000)
d.click(0.5, 0.4)  # "If of type float, it represents percentage coordinates."
d.double_click(500, 1000)
d.double_click(0.5, 0.4)
d.long_click(500, 1000)
d.long_click(0.5, 0.4)
d.swipe(0.5, 0.8, 0.5, 0.4, speed=2000)
d.input_text(0.5, 0.5, "adbcdfg")

# App Element
d(text="showToast").info
# {
#     "id": "",
#     "key": "",
#     "type": "Button",
#     "text": "showToast",
#     "description": "",
#     "isSelected": False,
#     "isChecked": False,
#     "isEnabled": True,
#     "isFocused": False,
#     "isCheckable": False,
#     "isClickable": True,
#     "isLongClickable": False,
#     "isScrollable": False,
#     "bounds": {
#         "left": 539,
#         "top": 1282,
#         "right": 832,
#         "bottom": 1412
#     },
#     "boundsCenter": {
#         "x": 685,
#         "y": 1347
#     }
# }

d(id="swiper").exists()
d(type="Button", text="tab_recrod").exists()
d(text="tab_recrod", isAfter=True).exists()
d(text="tab_recrod").click_if_exists()
d(type="Button", index=3).click()
d(text="tab_recrod").double_click()
d(text="tab_recrod").long_click()

component: ComponentData = d(type="ListItem", index=1).find_component()
d(type="ListItem").drag_to(component)

d(text="tab_recrod").input_text("abc")
d(text="tab_recrod").clear_text()
d(text="tab_recrod").pinch_in()
d(text="tab_recrod").pinch_out()

# Dump hierarchy
d.dump_hierarchy()

# Toast Watcher
d.toast_watcher.start()
d(type="Button", text="tab_recrod").click()  # 触发toast的操作
toast = d.toast_watcher.get()

Refer to

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hmdriver2-1.0.1.tar.gz (77.5 kB view details)

Uploaded Source

Built Distribution

hmdriver2-1.0.1-py3-none-any.whl (77.5 kB view details)

Uploaded Python 3

File details

Details for the file hmdriver2-1.0.1.tar.gz.

File metadata

  • Download URL: hmdriver2-1.0.1.tar.gz
  • Upload date:
  • Size: 77.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for hmdriver2-1.0.1.tar.gz
Algorithm Hash digest
SHA256 d8dd294bc2a9534e6aba48eeb9c8c4aa6713748480397d89fc18c3b80e6a3d6d
MD5 d194efac05096f2b40f1bdba8e617566
BLAKE2b-256 6d2b2e90bb9cc730858a541bfa61639ab6d082eec3c993d1f1433df39e587cdc

See more details on using hashes here.

File details

Details for the file hmdriver2-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: hmdriver2-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 77.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.5

File hashes

Hashes for hmdriver2-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 dbbfa72c34ce4332953616de10b2b6977981d453bdffc9e87d9e95a813014f41
MD5 1f21e5dff69a4fdb1f957622e78ab1d4
BLAKE2b-256 4c70ffa25b35b343ffd99b4de7bcc0902a47ba12d215b0012ba3797e6f950e71

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page