devhelmkit 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- devhelmkit-0.1.0/LICENSE +201 -0
- devhelmkit-0.1.0/MANIFEST.in +18 -0
- devhelmkit-0.1.0/PKG-INFO +411 -0
- devhelmkit-0.1.0/README.md +376 -0
- devhelmkit-0.1.0/__init__.py +44 -0
- devhelmkit-0.1.0/android/__init__.py +7 -0
- devhelmkit-0.1.0/android/driver.py +18 -0
- devhelmkit-0.1.0/assets/so/arm64-v8a/agent_v1.so +0 -0
- devhelmkit-0.1.0/assets/so/arm64-v8a/agent_v2.so +0 -0
- devhelmkit-0.1.0/assets/so/x86_64/agent.so +0 -0
- devhelmkit-0.1.0/core/__init__.py +3 -0
- devhelmkit-0.1.0/core/base_component.py +214 -0
- devhelmkit-0.1.0/core/base_driver.py +414 -0
- devhelmkit-0.1.0/core/base_window.py +25 -0
- devhelmkit-0.1.0/core/selector_spec.py +102 -0
- devhelmkit-0.1.0/devhelmkit.egg-info/PKG-INFO +411 -0
- devhelmkit-0.1.0/devhelmkit.egg-info/SOURCES.txt +115 -0
- devhelmkit-0.1.0/devhelmkit.egg-info/dependency_links.txt +1 -0
- devhelmkit-0.1.0/devhelmkit.egg-info/requires.txt +10 -0
- devhelmkit-0.1.0/devhelmkit.egg-info/top_level.txt +1 -0
- devhelmkit-0.1.0/entry.py +90 -0
- devhelmkit-0.1.0/exceptions.py +56 -0
- devhelmkit-0.1.0/harmony/__init__.py +3 -0
- devhelmkit-0.1.0/harmony/agent/__init__.py +7 -0
- devhelmkit-0.1.0/harmony/agent/so_manager.py +300 -0
- devhelmkit-0.1.0/harmony/config.py +124 -0
- devhelmkit-0.1.0/harmony/device/__init__.py +6 -0
- devhelmkit-0.1.0/harmony/device/hdc.py +430 -0
- devhelmkit-0.1.0/harmony/driver.py +1416 -0
- devhelmkit-0.1.0/harmony/finder/__init__.py +12 -0
- devhelmkit-0.1.0/harmony/finder/component_finder.py +336 -0
- devhelmkit-0.1.0/harmony/finder/popup_handler.py +81 -0
- devhelmkit-0.1.0/harmony/finder/selector_adapter.py +101 -0
- devhelmkit-0.1.0/harmony/finder/xpath_query.py +110 -0
- devhelmkit-0.1.0/harmony/rpc/__init__.py +12 -0
- devhelmkit-0.1.0/harmony/rpc/client.py +126 -0
- devhelmkit-0.1.0/harmony/rpc/proxy_v2.py +106 -0
- devhelmkit-0.1.0/harmony/rpc/remote_object.py +48 -0
- devhelmkit-0.1.0/harmony/uiobject.py +246 -0
- devhelmkit-0.1.0/harmony/uiwindow.py +43 -0
- devhelmkit-0.1.0/harmony/webview/__init__.py +17 -0
- devhelmkit-0.1.0/harmony/webview/chromedriver_manager.py +251 -0
- devhelmkit-0.1.0/harmony/webview/devtools_finder.py +131 -0
- devhelmkit-0.1.0/harmony/webview/webview_driver.py +326 -0
- devhelmkit-0.1.0/model/__init__.py +3 -0
- devhelmkit-0.1.0/model/action.py +147 -0
- devhelmkit-0.1.0/model/app_state.py +50 -0
- devhelmkit-0.1.0/model/constants.py +22 -0
- devhelmkit-0.1.0/model/display.py +32 -0
- devhelmkit-0.1.0/model/format_string.py +24 -0
- devhelmkit-0.1.0/model/input.py +50 -0
- devhelmkit-0.1.0/model/json_base.py +42 -0
- devhelmkit-0.1.0/model/keys.py +375 -0
- devhelmkit-0.1.0/model/match_pattern.py +15 -0
- devhelmkit-0.1.0/model/page.py +13 -0
- devhelmkit-0.1.0/model/params.py +42 -0
- devhelmkit-0.1.0/model/rect.py +58 -0
- devhelmkit-0.1.0/model/runnable.py +18 -0
- devhelmkit-0.1.0/pyproject.toml +81 -0
- devhelmkit-0.1.0/setup.cfg +4 -0
- devhelmkit-0.1.0/utils/__init__.py +3 -0
- devhelmkit-0.1.0/utils/logger.py +72 -0
- devhelmkit-0.1.0/utils/retry.py +46 -0
- devhelmkit-0.1.0/utils/timeout.py +64 -0
devhelmkit-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or Derivative
|
|
95
|
+
Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# sdist 包含清单
|
|
2
|
+
# 源码分发包只包含运行时必需文件,排除 tests/docs/.github
|
|
3
|
+
|
|
4
|
+
include LICENSE
|
|
5
|
+
include README.md
|
|
6
|
+
include pyproject.toml
|
|
7
|
+
|
|
8
|
+
# 运行时包源码
|
|
9
|
+
recursive-include assets *.so
|
|
10
|
+
|
|
11
|
+
# 排除测试、文档、CI 配置
|
|
12
|
+
recursive-exclude tests *
|
|
13
|
+
recursive-exclude docs *
|
|
14
|
+
recursive-exclude .github *
|
|
15
|
+
exclude .gitignore
|
|
16
|
+
exclude *.egg-info
|
|
17
|
+
recursive-exclude * __pycache__
|
|
18
|
+
recursive-exclude * *.py[cod]
|
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: devhelmkit
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: 跨平台 UI 自动化框架,当前聚焦 HarmonyOS
|
|
5
|
+
Author: devhelmkit contributors
|
|
6
|
+
License: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/yabi-zzh/devhelmkit
|
|
8
|
+
Project-URL: Repository, https://github.com/yabi-zzh/devhelmkit
|
|
9
|
+
Project-URL: Documentation, https://github.com/yabi-zzh/devhelmkit/tree/main/docs
|
|
10
|
+
Project-URL: Issues, https://github.com/yabi-zzh/devhelmkit/issues
|
|
11
|
+
Keywords: harmonyos,uiautomator,ui-automation,testing,hypium
|
|
12
|
+
Classifier: Development Status :: 3 - Alpha
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
22
|
+
Classifier: Topic :: Software Development :: Testing
|
|
23
|
+
Requires-Python: >=3.8
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Requires-Dist: Pillow>=9.0.0
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: pytest>=7.0; extra == "dev"
|
|
29
|
+
Requires-Dist: pytest-cov>=4.0; extra == "dev"
|
|
30
|
+
Requires-Dist: build>=1.0; extra == "dev"
|
|
31
|
+
Requires-Dist: twine>=4.0; extra == "dev"
|
|
32
|
+
Provides-Extra: webview
|
|
33
|
+
Requires-Dist: selenium>=4.0; extra == "webview"
|
|
34
|
+
Dynamic: license-file
|
|
35
|
+
|
|
36
|
+
# devhelmkit
|
|
37
|
+
|
|
38
|
+
跨平台 UI 自动化框架,当前聚焦 HarmonyOS。
|
|
39
|
+
|
|
40
|
+
[](LICENSE)
|
|
41
|
+
[](https://www.python.org)
|
|
42
|
+
[](#)
|
|
43
|
+
|
|
44
|
+
## 简介
|
|
45
|
+
|
|
46
|
+
devhelmkit 提供鸿蒙端 UI 自动化测试能力,通过 `hdc` 直连设备,无需依赖测试框架即可独立运行。
|
|
47
|
+
|
|
48
|
+
核心目标:
|
|
49
|
+
|
|
50
|
+
- **简洁 API**:`d(text="登录").click()`、`d.app_start()`、`d.dump_hierarchy()`
|
|
51
|
+
- **直连设备**:仅通过 `hdc` 通信,不依赖测试框架
|
|
52
|
+
- **跨平台抽象**:`BaseDriver` 契约层 + 平台具体实现,当前鸿蒙完整可用,Android 预留接口
|
|
53
|
+
- **保留高级能力**:鼠标、触控笔、指关节、触控板、多指手势等鸿蒙特性操作
|
|
54
|
+
|
|
55
|
+
## 特性
|
|
56
|
+
|
|
57
|
+
- 选择器链路:`d(text="xx")` / `d(id="xx")` / `d.xpath("//Text")`
|
|
58
|
+
- 控件操作:点击、长按、输入、拖拽、滑动、属性查询
|
|
59
|
+
- 设备控制:亮屏/息屏、解锁、按键、旋转、截图
|
|
60
|
+
- 应用管理:启动、停止、安装、卸载
|
|
61
|
+
- 高级手势:鼠标全套操作、触控笔(含压力)、指关节敲击、多指手势
|
|
62
|
+
- 触控板:多指滑动、滑动后停顿
|
|
63
|
+
- 事件监听:Toast 监听、UI 事件(对话框/窗口/组件事件)
|
|
64
|
+
- webview 自动化:通过 chromedriver + selenium 测试应用内 web 页面
|
|
65
|
+
- 双查找后端:uitest(设备端 RPC)+ uitree(本地 layout 解析)
|
|
66
|
+
- 资源管理:socket/端口转发自动清理,可选停止设备端守护进程
|
|
67
|
+
- 跨平台:支持 Windows / Linux / macOS,hdc 路径可配置
|
|
68
|
+
|
|
69
|
+
## 安装
|
|
70
|
+
|
|
71
|
+
### 前置条件
|
|
72
|
+
|
|
73
|
+
- **Python 3.8+**(支持 Windows / Linux / macOS)
|
|
74
|
+
- **HarmonyOS 设备**:已开启开发者模式与 USB 调试
|
|
75
|
+
- **hdc 命令行工具**:HarmonyOS Device Connector,用于与设备通信
|
|
76
|
+
|
|
77
|
+
#### 安装 hdc
|
|
78
|
+
|
|
79
|
+
hdc 随 HarmonyOS SDK 一起发布,获取方式:
|
|
80
|
+
|
|
81
|
+
1. 下载 [HarmonyOS SDK](https://developer.huawei.com/consumer/cn/download/)(选择 Command Line Tools for Windows/Linux/macOS)
|
|
82
|
+
2. 解压后,hdc 位于 `sdk/<version>/toolchains/` 目录下
|
|
83
|
+
3. 将该目录加入系统 `PATH` 环境变量
|
|
84
|
+
4. 验证安装:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
hdc -v
|
|
88
|
+
# HarmonyOS Device Connector vX.X.X
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
连接设备后验证:
|
|
92
|
+
|
|
93
|
+
```bash
|
|
94
|
+
hdc list targets
|
|
95
|
+
# FMR0223824042727
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
### 安装 devhelmkit
|
|
99
|
+
|
|
100
|
+
#### 方式一:pip 安装(推荐)
|
|
101
|
+
|
|
102
|
+
```bash
|
|
103
|
+
pip install devhelmkit
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
#### 方式二:从源码安装
|
|
107
|
+
|
|
108
|
+
```bash
|
|
109
|
+
git clone https://github.com/devhelmkit/devhelmkit.git
|
|
110
|
+
cd devhelmkit
|
|
111
|
+
pip install -e .
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
### 依赖
|
|
115
|
+
|
|
116
|
+
- `Pillow>=9.0.0`(截图功能)
|
|
117
|
+
|
|
118
|
+
## 快速上手
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
import devhelmkit
|
|
122
|
+
|
|
123
|
+
# 自动发现设备并连接
|
|
124
|
+
d = devhelmkit.connect()
|
|
125
|
+
|
|
126
|
+
# 启动应用
|
|
127
|
+
d.app_start("com.huawei.hmos.settings")
|
|
128
|
+
|
|
129
|
+
# 控件查找与操作
|
|
130
|
+
d(text="搜索").click()
|
|
131
|
+
d(className="TextInput").input_text("devhelmkit")
|
|
132
|
+
|
|
133
|
+
# 截图
|
|
134
|
+
d.screenshot().save("screen.png")
|
|
135
|
+
|
|
136
|
+
# 转储 UI 树
|
|
137
|
+
xml = d.dump_hierarchy()
|
|
138
|
+
|
|
139
|
+
# 关闭连接,释放 socket 与端口转发
|
|
140
|
+
d.close()
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
### 资源释放
|
|
144
|
+
|
|
145
|
+
推荐使用 `with` 语句或 `try/finally` 确保资源释放,无论是否异常都会
|
|
146
|
+
自动关闭 socket、清理 hdc 端口转发:
|
|
147
|
+
|
|
148
|
+
```python
|
|
149
|
+
import devhelmkit
|
|
150
|
+
|
|
151
|
+
with devhelmkit.connect() as d:
|
|
152
|
+
d.app_start("com.huawei.hmos.settings")
|
|
153
|
+
d(text="搜索").click()
|
|
154
|
+
# 退出 with 块时自动调用 close()
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
如需在关闭时同时停止设备端 uitest 守护进程(默认保留以便复用):
|
|
158
|
+
|
|
159
|
+
```python
|
|
160
|
+
# 方式一:运行时指定
|
|
161
|
+
d.close(stop_daemon=True)
|
|
162
|
+
|
|
163
|
+
# 方式二:通过配置项
|
|
164
|
+
from devhelmkit.harmony.config import HarmonyDriverConfig
|
|
165
|
+
|
|
166
|
+
config = HarmonyDriverConfig(stop_daemon_on_close=True)
|
|
167
|
+
d = devhelmkit.connect(config=config)
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
### 运行示例
|
|
171
|
+
|
|
172
|
+
仓库内置完整 demo,演示连接 → 操作 → 释放全流程:
|
|
173
|
+
|
|
174
|
+
```bash
|
|
175
|
+
# 基础示例(保留设备端守护进程)
|
|
176
|
+
python examples/quickstart.py
|
|
177
|
+
|
|
178
|
+
# 完整示例(退出时停止设备端守护进程)
|
|
179
|
+
python examples/quickstart.py --stop-daemon
|
|
180
|
+
|
|
181
|
+
# 指定设备序列号
|
|
182
|
+
python examples/quickstart.py FMR0223824042727
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
### 指定设备
|
|
186
|
+
|
|
187
|
+
```python
|
|
188
|
+
# 多设备时指定序列号
|
|
189
|
+
d = devhelmkit.connect(serial="1234567890ABCDEF")
|
|
190
|
+
|
|
191
|
+
# 显式指定平台
|
|
192
|
+
d = devhelmkit.connect(platform="harmony")
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
### 指定 hdc 路径
|
|
196
|
+
|
|
197
|
+
当 hdc 未加入系统 PATH,或需指定特定版本时:
|
|
198
|
+
|
|
199
|
+
```python
|
|
200
|
+
import devhelmkit
|
|
201
|
+
from devhelmkit.harmony.device.hdc import HdcDevice
|
|
202
|
+
|
|
203
|
+
# 全局设置 hdc 路径(影响后续所有连接)
|
|
204
|
+
HdcDevice.set_hdc_path("/path/to/hdc")
|
|
205
|
+
|
|
206
|
+
d = devhelmkit.connect()
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
或通过配置项:
|
|
210
|
+
|
|
211
|
+
```python
|
|
212
|
+
from devhelmkit.harmony.config import HarmonyDriverConfig
|
|
213
|
+
|
|
214
|
+
config = HarmonyDriverConfig(hdc_path="/path/to/hdc")
|
|
215
|
+
d = devhelmkit.connect(config=config)
|
|
216
|
+
```
|
|
217
|
+
|
|
218
|
+
## API 示例
|
|
219
|
+
|
|
220
|
+
### 控件操作
|
|
221
|
+
|
|
222
|
+
```python
|
|
223
|
+
# 等待控件出现
|
|
224
|
+
d(text="登录").wait(timeout=10)
|
|
225
|
+
|
|
226
|
+
# 输入文本
|
|
227
|
+
d(id="username").input_text("admin")
|
|
228
|
+
|
|
229
|
+
# 清空文本
|
|
230
|
+
d(id="username").clear_text()
|
|
231
|
+
|
|
232
|
+
# 长按
|
|
233
|
+
d(text="项目").long_click()
|
|
234
|
+
|
|
235
|
+
# 拖拽
|
|
236
|
+
d(text="A").drag_to(text="B")
|
|
237
|
+
|
|
238
|
+
# 获取属性
|
|
239
|
+
print(d(text="标题").info)
|
|
240
|
+
```
|
|
241
|
+
|
|
242
|
+
### 手势
|
|
243
|
+
|
|
244
|
+
```python
|
|
245
|
+
# 滑动
|
|
246
|
+
d.swipe(100, 500, 100, 100)
|
|
247
|
+
|
|
248
|
+
# 多指手势
|
|
249
|
+
d.two_finger_swipe((0, 400), (200, 400), (880, 400), (680, 400))
|
|
250
|
+
|
|
251
|
+
# 自定义手势
|
|
252
|
+
from devhelmkit.model.input import GestureAction
|
|
253
|
+
|
|
254
|
+
g = GestureAction()
|
|
255
|
+
g.add_step("move", 100, 200)
|
|
256
|
+
g.add_step("move", 200, 300)
|
|
257
|
+
d.inject_gesture(g, speed=1000)
|
|
258
|
+
```
|
|
259
|
+
|
|
260
|
+
### 鼠标操作
|
|
261
|
+
|
|
262
|
+
```python
|
|
263
|
+
# 鼠标点击(左键)
|
|
264
|
+
d.mouse_click((500, 500))
|
|
265
|
+
|
|
266
|
+
# 鼠标右键
|
|
267
|
+
d.mouse_click((500, 500), button_id=1)
|
|
268
|
+
|
|
269
|
+
# 鼠标滚轮
|
|
270
|
+
d.mouse_scroll((500, 500), "down", steps=3)
|
|
271
|
+
|
|
272
|
+
# 鼠标拖拽
|
|
273
|
+
d.mouse_drag((100, 100), (300, 300))
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
### 触控笔
|
|
277
|
+
|
|
278
|
+
```python
|
|
279
|
+
# 触控笔点击
|
|
280
|
+
d.pen_click((500, 500))
|
|
281
|
+
|
|
282
|
+
# 触控笔长按(带压力)
|
|
283
|
+
d.pen_long_click((500, 500), pressure=0.8)
|
|
284
|
+
|
|
285
|
+
# 触控笔方向滑动
|
|
286
|
+
d.pen_swipe("UP", distance=60)
|
|
287
|
+
```
|
|
288
|
+
|
|
289
|
+
### 事件监听
|
|
290
|
+
|
|
291
|
+
```python
|
|
292
|
+
# Toast 监听
|
|
293
|
+
d.start_listen_toast()
|
|
294
|
+
d(text="提交").click()
|
|
295
|
+
print("Toast:", d.get_latest_toast(timeout=3))
|
|
296
|
+
|
|
297
|
+
# 检查 Toast
|
|
298
|
+
if d.check_toast("保存成功", fuzzy="contains"):
|
|
299
|
+
print("操作成功")
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
### 设备控制
|
|
303
|
+
|
|
304
|
+
```python
|
|
305
|
+
# 亮屏/息屏
|
|
306
|
+
d.wake_up_display()
|
|
307
|
+
d.close_display()
|
|
308
|
+
|
|
309
|
+
# 按键
|
|
310
|
+
d.press_keycode(23) # 确认键
|
|
311
|
+
|
|
312
|
+
# 截图
|
|
313
|
+
img = d.screenshot()
|
|
314
|
+
img.save("capture.png")
|
|
315
|
+
|
|
316
|
+
# 安装应用
|
|
317
|
+
d.app_install("/path/to/app.hap")
|
|
318
|
+
```
|
|
319
|
+
|
|
320
|
+
### webview 自动化
|
|
321
|
+
|
|
322
|
+
webview 测试需要安装可选依赖 `selenium` 与 chromedriver:
|
|
323
|
+
|
|
324
|
+
```bash
|
|
325
|
+
# 安装 webview 可选依赖
|
|
326
|
+
pip install devhelmkit[webview]
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
chromedriver 需按设备 webview 版本下载,放置于目录:
|
|
330
|
+
|
|
331
|
+
```text
|
|
332
|
+
chromedriver_search_path/
|
|
333
|
+
├── chromedriver_114/
|
|
334
|
+
│ ├── chromedriver.exe # Windows
|
|
335
|
+
│ ├── chromedriver # Linux
|
|
336
|
+
│ └── chromedriver.mac # macOS
|
|
337
|
+
└── chromedriver_132/
|
|
338
|
+
├── chromedriver.exe
|
|
339
|
+
├── chromedriver
|
|
340
|
+
└── chromedriver.mac
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
使用方式:
|
|
344
|
+
|
|
345
|
+
```python
|
|
346
|
+
# 连接应用 webview
|
|
347
|
+
wv = d.webview(
|
|
348
|
+
"com.huawei.hmos.browser",
|
|
349
|
+
chromedriver_search_path="/path/to/chromedriver_search_path"
|
|
350
|
+
)
|
|
351
|
+
|
|
352
|
+
# 通过 selenium webdriver 操作页面
|
|
353
|
+
wv.driver.get("https://www.baidu.com")
|
|
354
|
+
wv.driver.find_element("id", "kw").send_keys("devhelmkit")
|
|
355
|
+
|
|
356
|
+
# 释放资源(移除端口转发 + quit webdriver + 停止 chromedriver)
|
|
357
|
+
wv.close()
|
|
358
|
+
```
|
|
359
|
+
|
|
360
|
+
## 架构
|
|
361
|
+
|
|
362
|
+
```text
|
|
363
|
+
devhelmkit/
|
|
364
|
+
├── core/ # 跨平台契约层(BaseDriver / BaseComponent / SelectorSpec)
|
|
365
|
+
├── model/ # 纯数据类型(Rect / KeyCode / GestureAction / ...)
|
|
366
|
+
├── harmony/ # HarmonyOS 平台实现
|
|
367
|
+
│ ├── driver.py # 平台驱动门面
|
|
368
|
+
│ ├── device/ # hdc 命令封装与 RPC 通道
|
|
369
|
+
│ ├── rpc/ # bin 模式 RPC 协议与远程对象管理
|
|
370
|
+
│ ├── finder/ # 控件查找(uitest + uitree 双后端)
|
|
371
|
+
│ ├── agent/ # 设备端 uitest 守护进程管理
|
|
372
|
+
│ └── webview/ # webview 自动化(chromedriver + selenium)
|
|
373
|
+
├── android/ # Android 平台预留(阶段四)
|
|
374
|
+
├── utils/ # 通用工具(日志/重试/超时)
|
|
375
|
+
├── assets/so/ # 设备端 agent.so 资产
|
|
376
|
+
├── examples/ # 示例代码(quickstart.py)
|
|
377
|
+
└── tests/ # 单元测试与集成测试
|
|
378
|
+
```
|
|
379
|
+
|
|
380
|
+
详细设计文档见 [docs/design/](docs/design/README.md)。
|
|
381
|
+
|
|
382
|
+
## 开发
|
|
383
|
+
|
|
384
|
+
### 运行测试
|
|
385
|
+
|
|
386
|
+
```bash
|
|
387
|
+
# 离线单元测试(无需设备)
|
|
388
|
+
python tests/test_api_offline.py
|
|
389
|
+
|
|
390
|
+
# 真机集成测试
|
|
391
|
+
python tests/test_device_info.py <设备SN>
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
### 代码结构约定
|
|
395
|
+
|
|
396
|
+
- `core/` 禁止依赖平台实现层
|
|
397
|
+
- `model/` 无内部依赖,可跨平台复用
|
|
398
|
+
- 平台实现层内部按 `device/`、`rpc/`、`finder/` 分包
|
|
399
|
+
- RPC 层不认识 UI 对象,设备通道不理解控件定位
|
|
400
|
+
|
|
401
|
+
## 贡献
|
|
402
|
+
|
|
403
|
+
欢迎提交 Issue 与 Pull Request。提交前请确保:
|
|
404
|
+
|
|
405
|
+
1. 代码通过离线测试:`python tests/test_api_offline.py`
|
|
406
|
+
2. 遵循现有代码风格与分层约束
|
|
407
|
+
3. 新增 API 需同步更新 [API 接口文档](docs/api_reference.md)
|
|
408
|
+
|
|
409
|
+
## 许可证
|
|
410
|
+
|
|
411
|
+
[Apache License 2.0](LICENSE)
|