lynx-e2e-appium 0.0.1__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.
Files changed (79) hide show
  1. lynx_e2e_appium-0.0.1/LICENSE +202 -0
  2. lynx_e2e_appium-0.0.1/PKG-INFO +13 -0
  3. lynx_e2e_appium-0.0.1/README.md +184 -0
  4. lynx_e2e_appium-0.0.1/lynx_e2e/__init__.py +0 -0
  5. lynx_e2e_appium-0.0.1/lynx_e2e/__version__.py +1 -0
  6. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/__init__.py +0 -0
  7. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/appium/__init__.py +0 -0
  8. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/appium/app.py +202 -0
  9. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/appium/device.py +10 -0
  10. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/appium/device_driver.py +380 -0
  11. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/appium/lynx_element.py +90 -0
  12. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/appium/lynx_view.py +96 -0
  13. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/config.py +133 -0
  14. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/core/__init__.py +0 -0
  15. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/core/app.py +351 -0
  16. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/core/debugger.py +195 -0
  17. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/core/debugger_mixin/__init__.py +0 -0
  18. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/core/debugger_mixin/dom.py +80 -0
  19. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/core/debugger_mixin/performance.py +60 -0
  20. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/core/debugger_mixin/runtime.py +45 -0
  21. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/core/debugger_mixin/screencast.py +50 -0
  22. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/core/debugger_mixin/testbench.py +47 -0
  23. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/core/document_tree.py +579 -0
  24. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/core/element_searcher.py +149 -0
  25. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/core/logger/__init__.py +0 -0
  26. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/core/logger/cdp_logger.py +66 -0
  27. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/core/logger/console_logger.py +46 -0
  28. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/core/lynx_driver.py +275 -0
  29. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/core/lynx_element_mixin.py +385 -0
  30. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/core/lynx_view_mixin.py +86 -0
  31. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/core/net/__init__.py +0 -0
  32. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/core/net/base_connector.py +44 -0
  33. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/core/net/receiver.py +203 -0
  34. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/core/net/sender.py +135 -0
  35. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/core/net/usb_connector.py +154 -0
  36. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/core/rectangle.py +193 -0
  37. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/core/upath.py +290 -0
  38. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/core/utils.py +34 -0
  39. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/device/__init__.py +0 -0
  40. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/device/adb/__init__.py +0 -0
  41. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/device/adb/adb.py +291 -0
  42. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/device/adb/adb_client.py +667 -0
  43. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/device/adb/exception.py +26 -0
  44. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/device/android_device_driver_mixin.py +51 -0
  45. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/device/device.py +338 -0
  46. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/device/device_driver.py +190 -0
  47. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/device/exception.py +8 -0
  48. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/device/resource.py +251 -0
  49. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/exception.py +104 -0
  50. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/manage/__init__.py +0 -0
  51. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/manage/case_runner.py +280 -0
  52. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/manage/exception.py +17 -0
  53. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/manage/loader.py +266 -0
  54. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/manage/management.py +157 -0
  55. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/manage/report.py +415 -0
  56. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/manage/test_result.py +577 -0
  57. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/testcase/__init__.py +0 -0
  58. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/testcase/retry.py +119 -0
  59. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/testcase/testcase.py +788 -0
  60. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/testcase/testcase_context.py +33 -0
  61. lynx_e2e_appium-0.0.1/lynx_e2e/_impl/utils.py +133 -0
  62. lynx_e2e_appium-0.0.1/lynx_e2e/api/__init__.py +0 -0
  63. lynx_e2e_appium-0.0.1/lynx_e2e/api/app.py +30 -0
  64. lynx_e2e_appium-0.0.1/lynx_e2e/api/config.py +33 -0
  65. lynx_e2e_appium-0.0.1/lynx_e2e/api/exception.py +6 -0
  66. lynx_e2e_appium-0.0.1/lynx_e2e/api/logger.py +33 -0
  67. lynx_e2e_appium-0.0.1/lynx_e2e/api/lynx_driver.py +23 -0
  68. lynx_e2e_appium-0.0.1/lynx_e2e/api/lynx_element.py +22 -0
  69. lynx_e2e_appium-0.0.1/lynx_e2e/api/lynx_view.py +22 -0
  70. lynx_e2e_appium-0.0.1/lynx_e2e/api/management.py +25 -0
  71. lynx_e2e_appium-0.0.1/lynx_e2e/api/testcase.py +29 -0
  72. lynx_e2e_appium-0.0.1/lynx_e2e/api/upath.py +56 -0
  73. lynx_e2e_appium-0.0.1/lynx_e2e_appium.egg-info/PKG-INFO +13 -0
  74. lynx_e2e_appium-0.0.1/lynx_e2e_appium.egg-info/SOURCES.txt +77 -0
  75. lynx_e2e_appium-0.0.1/lynx_e2e_appium.egg-info/dependency_links.txt +1 -0
  76. lynx_e2e_appium-0.0.1/lynx_e2e_appium.egg-info/requires.txt +4 -0
  77. lynx_e2e_appium-0.0.1/lynx_e2e_appium.egg-info/top_level.txt +1 -0
  78. lynx_e2e_appium-0.0.1/setup.cfg +4 -0
  79. lynx_e2e_appium-0.0.1/setup.py +64 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,13 @@
1
+ Metadata-Version: 2.1
2
+ Name: lynx-e2e-appium
3
+ Version: 0.0.1
4
+ Summary: Lynx E2E Driver
5
+ Author: gaohanqing
6
+ Author-email: gaohqnuaa@foxmail.com
7
+ License-File: LICENSE
8
+ Requires-Dist: appium-python-client==3.1.1
9
+ Requires-Dist: selenium==4.17.2
10
+ Requires-Dist: ujson
11
+ Requires-Dist: opencv-python
12
+
13
+ Lynx E2E Driver
@@ -0,0 +1,184 @@
1
+ ## What is lynx-e2e?
2
+
3
+ lynx-e2e is a UI automation framework customized for Lynx.
4
+
5
+ You will utilize the following capabilities through lynx-e2e:
6
+
7
+ - **Cross Platform:** Write end-to-end tests in Python for apps using Lynx (Android & iOS).
8
+ - **Test Management:** Lynx-E2E provides testcase managment ability. You can control the specific list of test cases for each run.
9
+ - **Inspect Lynx:** Through Lynx-E2E, you can search for, locate and operate any node in LynxView.
10
+
11
+ ## What Does a lynx-e2e Test Look Like?
12
+
13
+ This is a test for performing click operations on a simple Lynx demo page:
14
+
15
+ ```python
16
+ from lynx_e2e.api.app import LynxApp as LynxAppBase
17
+ from lynx_e2e.api.lynx_view import LynxView
18
+ from lynx_e2e.api.testcase import TestCase
19
+
20
+ class DemoTest(TestCase):
21
+ def pre_test(self):
22
+ self.start_step('--------Aquire Device--------')
23
+ self.device = self.acquire_device()
24
+ app = LynxApp(self.device)
25
+ self.app = app
26
+ super().pre_test()
27
+
28
+ def run_test(self, test=None):
29
+ self.app.connect_app_to_lynx_server()
30
+ time.sleep(2)
31
+ self.app.open_card("sslocal://lynxtest?local://automation/core/initData/template.js?width=720&height=1280&density=320")
32
+ lynxview = self.app.get_lynxview('lynxview', LynxView)
33
+
34
+ count = lynxview.get_by_test_tag("count")
35
+ button = lynxview.get_by_test_tag("button")
36
+ button.click()
37
+ test.wait_for_equal('setData failed', count_view, 'text', '1')
38
+
39
+ class LynxApp(LynxAppBase):
40
+ app_spec = {
41
+ "package_name": "com.lynx.example", # app package name
42
+ "init_device": True, # whether to wake up device
43
+ "process_name": "", # main process name of app
44
+ "start_activity": "com.lynx.example.LynxViewShellActivity", # leave it empty to be detected automatically
45
+ "grant_all_permissions": True, # grant all permissions before starting app
46
+ "clear_data": False, # pm clear app data
47
+ "kill_process": True # whether to kill previously started app
48
+ }
49
+
50
+ def __init__(self, *args, **kwargs):
51
+ kwargs['app_spec'] = self.app_spec
52
+ super(LynxApp, self).__init__(*args, **kwargs)
53
+
54
+ def open_card(self, url):
55
+ if url == '':
56
+ return
57
+ self.open_lynx_container(url)
58
+
59
+ if __name__ == '__main__':
60
+ DemoTest().debug_run()
61
+ ```
62
+
63
+ ## Using Guides
64
+
65
+ ### 1. Import lynx-e2e
66
+
67
+ You can introduce the following dependencies in the requirements.txt of the project.
68
+
69
+ ```python
70
+ # lynx-e2e
71
+ lynx-e2e-appium
72
+ # appium dependencies
73
+ appium-python-client==3.1.1
74
+ selenium==4.17.2
75
+ ```
76
+
77
+ ### 2. Set App Base Info
78
+
79
+ You need to inherit from the LynxApp class and set the basic information of the app under test in it, such as the packageName and so on.
80
+
81
+ ```python
82
+ from lynx_e2e.api.app import LynxApp as LynxAppBase
83
+
84
+ class LynxApp(LynxAppBase):
85
+ app_spec = {
86
+ "package_name": "com.lynx.example", # app package name
87
+ "start_activity": "com.lynx.example.LynxViewShellActivity", # leave it empty to be detected automatically
88
+ }
89
+
90
+ def __init__(self, *args, **kwargs):
91
+ kwargs['app_spec'] = self.app_spec
92
+ super(LynxApp, self).__init__(*args, **kwargs)
93
+ ```
94
+
95
+ These basic pieces of information will be converted by the Lynx-e2e framework into AppiumOptions recognized by Appium.
96
+
97
+ ### 3. Locate LynxView
98
+
99
+ You can use get_lynxview method from LynxApp to get the LynxView instance.
100
+ ```python
101
+ from lynx_e2e.api.lynx_view import LynxView
102
+ lynxview = app.get_lynxview('lynxview', LynxView)
103
+ ```
104
+
105
+ ### 4. Search Element in LynxView
106
+
107
+ We provide multiple methods for element location, such as by text, class, test_tag, etc. Among them, the test-tag is provided internally by Lynx and is used to provide a custom unique identifier for the internal elements of LynxView.
108
+
109
+ All of the above methods are encapsulated in the LynxView object and can be directly called through the LynxView object. See the list of methods from [search method](https://github.com/lynx-infra/lynx-e2e/blob/main/lynx_e2e/_impl/appium/lynx_view.py#L35)
110
+
111
+ ## Project structure
112
+
113
+ Next, the structure of the project engineering will be introduced.
114
+
115
+ ```python
116
+ .
117
+ |_____impl
118
+ | |____testcase
119
+ | | |____testcase.py
120
+ | | |____retry.py
121
+ | | |____testcase_context.py
122
+ | |____exception.py
123
+ | |____config.py
124
+ | |____core # Implementation of core functions.
125
+ | | |____net # Communicate with LynxDevtool through socket.
126
+ | | | |____usb_connector.py
127
+ | | | |____sender.py
128
+ | | | |____base_connector.py
129
+ | | | |____receiver.py
130
+ | | |____upath.py
131
+ | | |____logger
132
+ | | | |____cdp_logger.py
133
+ | | | |____console_logger.py
134
+ | | |____element_searcher.py
135
+ | | |____document_tree.py
136
+ | | |____debugger.py
137
+ | | |____lynx_driver.py
138
+ | | |____utils.py
139
+ | | |____debugger_mixin # Capability enhancements based on Devtool, including taking screenshots, test bench recording and playback, etc.
140
+ | | | |____screencast.py
141
+ | | | |____testbench.py
142
+ | | | |____runtime.py
143
+ | | | |____performance.py
144
+ | | | |____dom.py
145
+ | | |____lynx_element_mixin.py
146
+ | | |____rectangle.py
147
+ | | |____app.py
148
+ | | |____lynx_view_mixin.py
149
+ | |____utils.py
150
+ | |____manage # Used for test case management and outputting the results of test runs.
151
+ | | |____test_result.py
152
+ | | |____exception.py
153
+ | | |____case_runner.py
154
+ | | |____loader.py
155
+ | | |____management.py
156
+ | | |____report.py
157
+ | |____device
158
+ | | |____exception.py
159
+ | | |____android_device_driver_mixin.py
160
+ | | |____device.py
161
+ | | |____resource.py
162
+ | | |____adb
163
+ | | | |____exception.py
164
+ | | | |____adb_client.py
165
+ | | | |____adb.py
166
+ | | |____device_driver.py
167
+ | |____appium
168
+ | | |____device.py
169
+ | | |____lynx_element.py
170
+ | | |____device_driver.py
171
+ | | |____lynx_view.py
172
+ | | |____app.py
173
+ |____api # It contains all the callable objects encapsulated for the automation scripts.
174
+ | |____exception.py
175
+ | |____upath.py
176
+ | |____config.py
177
+ | |____testcase.py
178
+ | |____logger.py
179
+ | |____lynx_driver.py
180
+ | |____lynx_element.py
181
+ | |____lynx_view.py
182
+ | |____management.py
183
+ | |____app.py
184
+ ```
File without changes
@@ -0,0 +1 @@
1
+ version = "0.0.1"
File without changes
@@ -0,0 +1,202 @@
1
+ # Copyright 2024 The Lynx Authors. All rights reserved.
2
+ # Licensed under the Apache License Version 2.0 that can be found in the
3
+ # LICENSE file in the root directory of this source tree.
4
+
5
+ import os
6
+ import time
7
+
8
+ from appium import webdriver
9
+ from appium.options.common.base import AppiumOptions
10
+ from appium.options.ios import XCUITestOptions
11
+ from appium.webdriver.common.appiumby import AppiumBy
12
+
13
+ from .lynx_element import LynxElement
14
+ from .lynx_view import LynxView
15
+ from ..core.app import App as E2EBaseApp, LynxAppMixin
16
+ from ..core.logger import cdp_logger
17
+ from ..core.lynx_driver import LynxDriver
18
+ from ..core.upath import UPath
19
+ from ..exception import LynxNotFoundException
20
+
21
+
22
+ DEFAULT_APPIUM_SERVER_HOST = "127.0.0.1"
23
+ DEFAULT_APPIUM_SERVER_PORT = 4723
24
+
25
+
26
+ class CommonApp(E2EBaseApp):
27
+ def __init__(self, *args, **kwargs):
28
+ self._device = args[0]
29
+ self._server_host = os.environ.get('server_host', DEFAULT_APPIUM_SERVER_HOST)
30
+ self._server_port = os.environ.get('server_port', DEFAULT_APPIUM_SERVER_PORT)
31
+ if 'app_spec' not in kwargs:
32
+ raise ValueError("app_spec is required in app init!")
33
+ options = self._transform_app_spec(kwargs['app_spec'])
34
+ self._appium_driver = webdriver.Remote(f"{self._server_host}:{self._server_port}", options=options)
35
+ E2EBaseApp.__init__(self, device=args[0], app_spec=kwargs['app_spec'])
36
+ self._device.set_appium_driver(self._appium_driver)
37
+ time.sleep(5)
38
+
39
+ def _transform_app_spec(self, app_spec):
40
+ """transform app_spec to desired_capabilities for appium
41
+ app_spec = {
42
+ "package_name": "com.lynx.example", # For Android only
43
+ "init_device": True, # whether to wake up device
44
+ "process_name": "", # main process name of app
45
+ "start_activity": "", # leave it empty to be detected automatically
46
+ "grant_all_permissions": True, # grant all permissions before starting app
47
+ "clear_data": True, # pm clear app data
48
+ "kill_process": True, # whether to kill previously started app
49
+ "bundle_id": "com.lynx.example", # For iOS only
50
+ }
51
+
52
+ Args:
53
+ app_spec (_type_): _description_
54
+ """
55
+ raise NotImplementedError()
56
+
57
+ def get_controller(self, tag, index=0):
58
+ """Find specific view by tag in current window
59
+
60
+ Args:
61
+ tag (str): search condition
62
+ index (int, optional): search contidion when there are multiple views with the same tag in the window.
63
+ """
64
+ elements = self._appium_driver.find_elements(AppiumBy.XPATH, f"//*[@view-tag='{tag}']")
65
+ if len(elements) == 0:
66
+ raise LynxNotFoundException("Can't find lynxview on current window")
67
+ if len(elements) < index:
68
+ raise LynxNotFoundException(f"In the current window, there are only {len(elements)} elements with tag {tag}.\
69
+ The element at {index} cannot be obtained.")
70
+ path = UPath(predicates=[{"name": "lynx-test-tag", "value": tag, "operator": "=="}], index=index)
71
+ return LynxElement(elements[index], path=path, root=None)
72
+
73
+ def get_page_root(self):
74
+ raise NotImplementedError()
75
+
76
+ def get_lynxview(self, tag, _):
77
+ """Find lynxview by tag in current window
78
+
79
+ Args:
80
+ tag (_type_): _description_
81
+ lynxview_type (LynxView): _description_
82
+ """
83
+ elements = self._appium_driver.find_elements(AppiumBy.XPATH, f"//*[@view-tag='{tag}']")
84
+ if len(elements) == 0:
85
+ raise LynxNotFoundException("Can't find lynxview on current window")
86
+ return LynxView(elements[0], app=self, root=self.get_page_root())
87
+
88
+ def add_cleanup(self, msg, func, *args, **kwargs):
89
+ """add cleanup action to be done at the end of testcase execution
90
+
91
+ :param msg: indication message for cleanup action
92
+ :type msg: str
93
+ :param func: a callable object to be invoked
94
+ :type func: function
95
+ :param args: positional arguments to be passed to func
96
+ :type args: list
97
+ :param kwargs: keyword arguments to be passed to func
98
+ :type kwargs: dict
99
+ :return index: an index to identify a cleanup action for remove_cleanup
100
+ :rtype index: int
101
+ """
102
+ if self._testcase:
103
+ return self._testcase.add_cleanup(msg, func, *args, **kwargs)
104
+ else:
105
+ cdp_logger.warning(
106
+ "you may need to do explicit cleanup for: [%s]%s" % (msg, func))
107
+
108
+ def get_lynx_driver(self, lynxview):
109
+ cdp_logger.warning("[Appium]:start to get_lynx_driver")
110
+ if self.lynxDebug is None:
111
+ cdp_logger.warning("[Appium]:lynxDebug is not initialized, it need launch connect_app_to_lynx_server")
112
+ self.connect_app_to_lynx_server(over_usb=True)
113
+ return LynxDriver(lynxview, lynx_debugger=self.lynxDebug, **lynxview.view_spec)
114
+
115
+ def get_pid(self):
116
+ '''get current process id
117
+ '''
118
+ return None
119
+
120
+
121
+ class AndroidApp(LynxAppMixin, CommonApp):
122
+ def __init__(self, *args, **kwargs):
123
+ LynxAppMixin.__init__(self, *args, **kwargs)
124
+ CommonApp.__init__(self, *args, **kwargs)
125
+
126
+ def _transform_app_spec(self, app_spec):
127
+ """transform app_spec to desired_capabilities for appium
128
+ app_spec = {
129
+ "package_name": "com.lynx.example", # For Android only
130
+ "init_device": True, # whether to wake up device
131
+ "process_name": "", # main process name of app
132
+ "start_activity": "", # leave it empty to be detected automatically
133
+ "grant_all_permissions": True, # grant all permissions before starting app
134
+ "clear_data": True, # pm clear app data
135
+ "kill_process": True, # whether to kill previously started app
136
+ "bundle_id": "com.lynx.example", # For iOS only
137
+ }
138
+
139
+ Args:
140
+ app_spec (_type_): _description_
141
+ """
142
+ desired_capabilities = {
143
+ "udid": self._device.udid,
144
+ "deviceName": self._device.udid,
145
+ }
146
+ desired_capabilities["platformName"] = "Android"
147
+ desired_capabilities["automationName"] = "espresso"
148
+ desired_capabilities["espressoBuildConfig"] = '{"kotlin":"1.6.21","additionalAndroidTestDependencies": ' + '["androidx.lifecycle:lifecycle-extensions:2.2.0"]}'
149
+ desired_capabilities["appPackage"] = app_spec.get("package_name", None)
150
+ if 'start_activity' in app_spec and len(app_spec['start_activity']) > 0:
151
+ desired_capabilities['appActivity'] = app_spec.get('start_activity')
152
+ if 'app' in app_spec and len(app_spec['app']) > 0:
153
+ desired_capabilities['app'] = app_spec.get('app')
154
+ desired_capabilities['platformVersion'] = self._device.os_version
155
+ return AppiumOptions().load_capabilities(desired_capabilities)
156
+
157
+ def has_keyboard(self):
158
+ focused_edit_text = self._appium_driver.find_elements(AppiumBy.XPATH, "//*[@class='android.widget.EditText' and @focused='true']")
159
+ if focused_edit_text:
160
+ return True
161
+ else:
162
+ return False
163
+
164
+ def restart(self, **kwargs):
165
+ self._appium_driver.terminate_app(self._app_spec['package_name'])
166
+ time.sleep(3)
167
+ self._appium_driver.activate_app(self._app_spec['package_name'])
168
+
169
+ def get_page_root(self):
170
+ return self._appium_driver.find_element(AppiumBy.CLASS_NAME, 'com.android.internal.policy.DecorView')
171
+
172
+ def is_app_crashed(self):
173
+ package_name = self._device.get_current_process()
174
+ return package_name == self.app_spec["package_name"]
175
+
176
+
177
+ class iOSApp(LynxAppMixin, CommonApp):
178
+ def __init__(self, *args, **kwargs):
179
+ LynxAppMixin.__init__(self, *args, **kwargs)
180
+ CommonApp.__init__(self, *args, **kwargs)
181
+
182
+ def _transform_app_spec(self, app_spec):
183
+ desired_capabilities = {
184
+ "udid": self._device.udid,
185
+ "deviceName": self._device.udid,
186
+ "platformName": "iOS",
187
+ "bundleId": app_spec.get('bundleId', None),
188
+ "automationName": "XCUITest"
189
+ }
190
+ return XCUITestOptions().load_capabilities(desired_capabilities)
191
+
192
+ def restart(self, **kwargs):
193
+ self._appium_driver.terminate_app(self._app_spec['bundleId'])
194
+ time.sleep(3)
195
+ self._appium_driver.activate_app(self._app_spec['bundleId'])
196
+
197
+ def get_page_root(self):
198
+ return self._appium_driver.find_elements(AppiumBy.XPATH, "/*")
199
+
200
+ def is_app_crashed(self):
201
+ bundle_id = self._device.get_current_process()
202
+ return bundle_id == self.app_spec["bundle_id"]
@@ -0,0 +1,10 @@
1
+ # Copyright 2024 The Lynx Authors. All rights reserved.
2
+ # Licensed under the Apache License Version 2.0 that can be found in the
3
+ # LICENSE file in the root directory of this source tree.
4
+
5
+ from ..device.device import Device as BaseDevice
6
+
7
+ class AndroidDevice(BaseDevice):
8
+
9
+ def set_appium_driver(self, driver):
10
+ self._driver.set_appium_driver(driver)