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)
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="showToast").exists()
d(text="showToast", isAfter=True).exists()
d(text="showToast").click_if_exists()
d(type="Button", index=3).click()
d(text="showToast").double_click()
d(text="showToast").long_click()

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

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

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.0.tar.gz (76.4 kB view details)

Uploaded Source

Built Distribution

hmdriver2-1.0.0-py3-none-any.whl (76.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: hmdriver2-1.0.0.tar.gz
  • Upload date:
  • Size: 76.4 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.0.tar.gz
Algorithm Hash digest
SHA256 2438df94d6362c822356a569828099368a5364eef626f264f63694cd09894283
MD5 a8fd5ca67a22e12589ed2113d2771fde
BLAKE2b-256 db2a24807685e9a68b929ea20d5f954856ac83b492248686c0553f971402f52a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: hmdriver2-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 76.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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1f771e6f65937e3fc3c40f29c5a2f68fb5eef06717afe590282522e2176cd715
MD5 00484c341abbea38c18f4922ad5e9075
BLAKE2b-256 0021a2a9c79c218c6337f6c880e42cbeeaf0f5a0b2a1316b14a5d3a550609674

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