Writing properties for HarmonyOS
HarmonyOS UI Control Viewer Tool: uiviewer Tutorial
We use uiviewer to support HarmonyOS. The following command will install and start uiviewer for you.
pip install -U uiviewer
python -m uiviewer
This will start a host server at http://localhost:8000/ by default. You can access the tool via a browser.
HarmonyOS PDL API
We use hmdriver2 as the PDL API, which is similar to uiautomator2.
In HarmonyOS, the globally unique selector specified by application developers is id (similar to resourceId in Android). When there is no id, you can use properties like text and description to locate the device. You can fill in multiple control properties in the selector to ensure that you can as accurately locate the target control.
You can view the usage manual of hmdriver2 at github-hmdriver2.
Here are some examples of HarmonyOS PDL.
# 点击 id 为 "wifi_entry.icon" 的控件
d(id="wifi_entry.icon").click()
# 点击 id 为 "display_settings.title" 且text为 "Display" 的控件
d(id="display_settings.title", text="Display").long_click()
# 向 id 为 "url_input_in_search" 的控件输入 "hello"
d(id="url_input_in_search").input_text("hello")
Starting Kea for HarmonyOS
You should specify your computer’s system in config.yml. You can refer to the tutorial of YAML Configuration.
Here is an example.
# config.yml
# 声明电脑的系统为 Linux
env: Linux
You can specify other parameters in the terminal or in config.yml. For more details, please check the provided config.yml.
If you have specified all the necessary parameters in config.yml, you can start kea with kea -load_config. The following example is a fully configured example that can be started with kea -load_config.
# env: 你电脑的系统 (例如 windows, macOS, Linux)
env: Linux
# system: 目标 HarmonyOS
system: harmonyOS
device: 127.0.0.1:5555 # 仅连接一个设备时可不填,就自动指定
app_path: example/example.hap # 应用安装包
policy: random # 输入策略
count: 100
properties:
- example/example_hm_property.py
# package 用于通过包名指定待测应用。此选项和通过app_path指定安装包请二选一。
# 当你使用包名指定待测应用时,你一般需要让keep_app为True,这让测试停止时应用不会被卸载。
package: com.youku.next
keep_app: True