mangoautomation 1.1.23__py3-none-any.whl → 1.1.24__py3-none-any.whl
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.
Potentially problematic release.
This version of mangoautomation might be problematic. Click here for more details.
- mangoautomation/mangos/__pycache__/__init__.cpython-310.pyc +0 -0
- mangoautomation/mangos/mangos.cp310-win_amd64.pyd +0 -0
- mangoautomation/mangos/mangos.cp312-win_amd64.pyd +0 -0
- mangoautomation/mangos/mangos.cpython-310-darwin.so +0 -0
- mangoautomation/mangos/mangos.cpython-310-x86_64-linux-gnu.so +0 -0
- mangoautomation/mangos/mangos.cpython-312-darwin.so +0 -0
- mangoautomation/mangos/mangos.cpython-312-x86_64-linux-gnu.so +0 -0
- mangoautomation/uidrives/_driver_object.py +5 -36
- mangoautomation-1.1.24.dist-info/METADATA +42 -0
- mangoautomation-1.1.24.dist-info/RECORD +48 -0
- {mangoautomation-1.1.23.dist-info → mangoautomation-1.1.24.dist-info}/WHEEL +1 -1
- tests/demo1.py +94 -21
- tests/get_ope.py +12 -3
- mangoautomation/uidrives/android/_application.py +0 -70
- mangoautomation/uidrives/android/_assertion.py +0 -90
- mangoautomation/uidrives/android/_customization.py +0 -15
- mangoautomation/uidrives/android/_element.py +0 -169
- mangoautomation/uidrives/android/_equipment.py +0 -151
- mangoautomation/uidrives/android/_new_android.py +0 -54
- mangoautomation/uidrives/android/_page.py +0 -116
- mangoautomation/uidrives/web/async_web/__init__.py +0 -165
- mangoautomation/uidrives/web/async_web/_assertion.py +0 -303
- mangoautomation/uidrives/web/async_web/_browser.py +0 -112
- mangoautomation/uidrives/web/async_web/_customization.py +0 -14
- mangoautomation/uidrives/web/async_web/_element.py +0 -240
- mangoautomation/uidrives/web/async_web/_input_device.py +0 -82
- mangoautomation/uidrives/web/async_web/_new_browser.py +0 -153
- mangoautomation/uidrives/web/async_web/_page.py +0 -63
- mangoautomation/uidrives/web/sync_web/__init__.py +0 -160
- mangoautomation/uidrives/web/sync_web/_assertion.py +0 -304
- mangoautomation/uidrives/web/sync_web/_browser.py +0 -112
- mangoautomation/uidrives/web/sync_web/_customization.py +0 -14
- mangoautomation/uidrives/web/sync_web/_element.py +0 -240
- mangoautomation/uidrives/web/sync_web/_input_device.py +0 -80
- mangoautomation/uidrives/web/sync_web/_new_browser.py +0 -153
- mangoautomation/uidrives/web/sync_web/_page.py +0 -61
- mangoautomation-1.1.23.dist-info/METADATA +0 -34
- mangoautomation-1.1.23.dist-info/RECORD +0 -71
- {mangoautomation-1.1.23.dist-info → mangoautomation-1.1.24.dist-info/licenses}/LICENSE +0 -0
- {mangoautomation-1.1.23.dist-info → mangoautomation-1.1.24.dist-info}/top_level.txt +0 -0
|
@@ -1,151 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
# @Project: 芒果测试平台
|
|
3
|
-
# @Description:
|
|
4
|
-
# @Time : 03-09-09 3:17
|
|
5
|
-
# @Author : 毛鹏
|
|
6
|
-
from time import sleep
|
|
7
|
-
|
|
8
|
-
from mangotools.decorator import sync_method_callback
|
|
9
|
-
from mangotools.models import MethodModel
|
|
10
|
-
from ...tools import Meta
|
|
11
|
-
from ...uidrives._base_data import BaseData
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class AndroidEquipment(metaclass=Meta):
|
|
15
|
-
"""设备操作"""
|
|
16
|
-
|
|
17
|
-
def __init__(self, base_data: BaseData):
|
|
18
|
-
self.base_data = base_data
|
|
19
|
-
|
|
20
|
-
@sync_method_callback('android', '设备操作', 1, [
|
|
21
|
-
MethodModel(n='等待时间', f='_time', p='请输入等待时间', d=True)])
|
|
22
|
-
def a_sleep(self, time_: int):
|
|
23
|
-
"""强制等待"""
|
|
24
|
-
sleep(time_)
|
|
25
|
-
|
|
26
|
-
@sync_method_callback('android', '设备操作', 2)
|
|
27
|
-
def a_screen_on(self):
|
|
28
|
-
"""打开屏幕"""
|
|
29
|
-
self.base_data.android.screen_on()
|
|
30
|
-
self.a_sleep(1)
|
|
31
|
-
|
|
32
|
-
@sync_method_callback('android', '设备操作', 3)
|
|
33
|
-
def a_screen_off(self):
|
|
34
|
-
"""关闭屏幕"""
|
|
35
|
-
self.base_data.android.screen_off()
|
|
36
|
-
self.a_sleep(1)
|
|
37
|
-
|
|
38
|
-
@sync_method_callback('android', '设备操作', 4)
|
|
39
|
-
def a_swipe_left(self):
|
|
40
|
-
"""获取屏幕开关状态"""
|
|
41
|
-
self.base_data.android.info.get('screenOn')
|
|
42
|
-
|
|
43
|
-
@sync_method_callback('android', '设备操作', 5)
|
|
44
|
-
def a_get_window_size(self):
|
|
45
|
-
"""提取屏幕尺寸"""
|
|
46
|
-
w, h = self.base_data.android.window_size()
|
|
47
|
-
return w, h
|
|
48
|
-
|
|
49
|
-
@sync_method_callback('android', '设备操作', 6, [
|
|
50
|
-
MethodModel(n='文件路径', f='file_path', p='请输入计算机文件路径', d=True),
|
|
51
|
-
MethodModel(n='手机目录', f='catalogue', p='请输入设备目录', d=True)])
|
|
52
|
-
def a_push(self, file_path, catalogue):
|
|
53
|
-
"""推送一个文件到设备"""
|
|
54
|
-
self.base_data.android.push(file_path, catalogue)
|
|
55
|
-
|
|
56
|
-
@sync_method_callback('android', '设备操作', 7, [
|
|
57
|
-
MethodModel(n='文件路径', f='feli_path', p='请输入设备文件路径', d=True),
|
|
58
|
-
MethodModel(n='手机目录', f='catalogue', p='请输入计算机目录', d=True)])
|
|
59
|
-
def a_pull(self, feli_path, catalogue):
|
|
60
|
-
"""提取文件"""
|
|
61
|
-
self.base_data.android.pull(feli_path, catalogue)
|
|
62
|
-
|
|
63
|
-
@sync_method_callback('android', '设备操作', 8)
|
|
64
|
-
def a_unlock(self):
|
|
65
|
-
"""解锁屏幕"""
|
|
66
|
-
self.base_data.android.unlock()
|
|
67
|
-
|
|
68
|
-
@sync_method_callback('android', '设备操作', 9)
|
|
69
|
-
def a_press_home(self):
|
|
70
|
-
"""按home键"""
|
|
71
|
-
self.base_data.android.press('home')
|
|
72
|
-
|
|
73
|
-
@sync_method_callback('android', '设备操作', 10)
|
|
74
|
-
def a_press_back(self):
|
|
75
|
-
"""按back键"""
|
|
76
|
-
self.base_data.android.press('back')
|
|
77
|
-
|
|
78
|
-
@sync_method_callback('android', '设备操作', 11)
|
|
79
|
-
def a_press_left(self):
|
|
80
|
-
"""按left键"""
|
|
81
|
-
self.base_data.android.press('left')
|
|
82
|
-
|
|
83
|
-
@sync_method_callback('android', '设备操作', 12)
|
|
84
|
-
def a_press_right(self):
|
|
85
|
-
"""按right键"""
|
|
86
|
-
self.base_data.android.press('right')
|
|
87
|
-
|
|
88
|
-
@sync_method_callback('android', '设备操作', 13)
|
|
89
|
-
def a_press_up(self):
|
|
90
|
-
"""按up键"""
|
|
91
|
-
self.base_data.android.press('up')
|
|
92
|
-
|
|
93
|
-
@sync_method_callback('android', '设备操作', 14)
|
|
94
|
-
def a_press_down(self):
|
|
95
|
-
"""按down键"""
|
|
96
|
-
self.base_data.android.press('down')
|
|
97
|
-
|
|
98
|
-
@sync_method_callback('android', '设备操作', 15)
|
|
99
|
-
def a_press_center(self):
|
|
100
|
-
"""按center键"""
|
|
101
|
-
self.base_data.android.press('center')
|
|
102
|
-
|
|
103
|
-
@sync_method_callback('android', '设备操作', 16)
|
|
104
|
-
def a_press_menu(self):
|
|
105
|
-
"""按menu键"""
|
|
106
|
-
self.base_data.android.press('menu')
|
|
107
|
-
|
|
108
|
-
@sync_method_callback('android', '设备操作', 17)
|
|
109
|
-
def a_press_search(self):
|
|
110
|
-
"""按search键"""
|
|
111
|
-
self.base_data.android.press('search')
|
|
112
|
-
|
|
113
|
-
@sync_method_callback('android', '设备操作', 18)
|
|
114
|
-
def a_press_enter(self):
|
|
115
|
-
"""按enter键"""
|
|
116
|
-
self.base_data.android.press('enter')
|
|
117
|
-
|
|
118
|
-
@sync_method_callback('android', '设备操作', 19)
|
|
119
|
-
def a_press_delete(self):
|
|
120
|
-
"""按delete键"""
|
|
121
|
-
self.base_data.android.press('delete')
|
|
122
|
-
|
|
123
|
-
@sync_method_callback('android', '设备操作', 20)
|
|
124
|
-
def a_press_recent(self):
|
|
125
|
-
"""按recent键"""
|
|
126
|
-
self.base_data.android.press('recent')
|
|
127
|
-
|
|
128
|
-
@sync_method_callback('android', '设备操作', 21)
|
|
129
|
-
def a_press_volume_up(self):
|
|
130
|
-
"""按volume_up键"""
|
|
131
|
-
self.base_data.android.press('volume_up')
|
|
132
|
-
|
|
133
|
-
@sync_method_callback('android', '设备操作', 22)
|
|
134
|
-
def a_press_volume_down(self):
|
|
135
|
-
"""按volume_down键"""
|
|
136
|
-
self.base_data.android.press('volume_down')
|
|
137
|
-
|
|
138
|
-
@sync_method_callback('android', '设备操作', 23)
|
|
139
|
-
def a_press_volume_mute(self):
|
|
140
|
-
"""按volume_mute键"""
|
|
141
|
-
self.base_data.android.press('volume_mute')
|
|
142
|
-
|
|
143
|
-
@sync_method_callback('android', '设备操作', 24)
|
|
144
|
-
def a_press_camera(self):
|
|
145
|
-
"""按camera键"""
|
|
146
|
-
self.base_data.android.press('camera')
|
|
147
|
-
|
|
148
|
-
@sync_method_callback('android', '设备操作', 25)
|
|
149
|
-
def a_press_power(self):
|
|
150
|
-
"""按power键"""
|
|
151
|
-
self.base_data.android.press('power')
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
# @Project: 芒果测试平台
|
|
3
|
-
# @Description:
|
|
4
|
-
# @Time : 2024-05-23 15:05
|
|
5
|
-
# @Author : 毛鹏
|
|
6
|
-
|
|
7
|
-
from typing import Optional
|
|
8
|
-
|
|
9
|
-
import uiautomator2 as u2
|
|
10
|
-
from adbutils import AdbTimeout
|
|
11
|
-
from uiautomator2 import ConnectError
|
|
12
|
-
|
|
13
|
-
from ...exceptions import MangoAutomationError
|
|
14
|
-
from ...exceptions.error_msg import ERROR_MSG_0042, ERROR_MSG_0045, ERROR_MSG_0040
|
|
15
|
-
|
|
16
|
-
"""
|
|
17
|
-
python -m uiautomator2 init
|
|
18
|
-
python -m weditor
|
|
19
|
-
|
|
20
|
-
"""
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
class NewAndroid:
|
|
24
|
-
|
|
25
|
-
def __init__(self, and_equipment):
|
|
26
|
-
self.and_equipment = and_equipment
|
|
27
|
-
self.info: Optional[dict | None] = None
|
|
28
|
-
self.example_dict = []
|
|
29
|
-
|
|
30
|
-
def new_android(self):
|
|
31
|
-
if self.and_equipment is None:
|
|
32
|
-
raise MangoAutomationError(*ERROR_MSG_0042)
|
|
33
|
-
try:
|
|
34
|
-
|
|
35
|
-
android = u2.connect(self.and_equipment)
|
|
36
|
-
self.info = android.info
|
|
37
|
-
# msg = f"设备启动成功!产品名称:{self.info.get('productName')}"
|
|
38
|
-
self.example_dict.append({
|
|
39
|
-
'config': self.and_equipment,
|
|
40
|
-
'info': self.info,
|
|
41
|
-
'android': android
|
|
42
|
-
})
|
|
43
|
-
except ConnectError:
|
|
44
|
-
raise MangoAutomationError(*ERROR_MSG_0040, value=(self.and_equipment,))
|
|
45
|
-
except RuntimeError:
|
|
46
|
-
raise MangoAutomationError(*ERROR_MSG_0045, value=(self.and_equipment,))
|
|
47
|
-
except (AdbTimeout, TimeoutError):
|
|
48
|
-
raise MangoAutomationError(*ERROR_MSG_0040, value=(self.and_equipment,))
|
|
49
|
-
else:
|
|
50
|
-
android.implicitly_wait(10)
|
|
51
|
-
return android
|
|
52
|
-
|
|
53
|
-
def close_android(self):
|
|
54
|
-
pass
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
# @Project: 芒果测试平台
|
|
3
|
-
# @Description: # @Time : 2023/4/6 13:31
|
|
4
|
-
# @Author : 毛鹏
|
|
5
|
-
import os.path
|
|
6
|
-
|
|
7
|
-
from uiautomator2 import Direction
|
|
8
|
-
|
|
9
|
-
from mangotools.decorator import sync_method_callback
|
|
10
|
-
from mangotools.models import MethodModel
|
|
11
|
-
from ...tools import Meta
|
|
12
|
-
from ...uidrives._base_data import BaseData
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class AndroidPage(metaclass=Meta):
|
|
16
|
-
"""页面操作"""
|
|
17
|
-
|
|
18
|
-
def __init__(self, base_data: BaseData):
|
|
19
|
-
self.base_data = base_data
|
|
20
|
-
|
|
21
|
-
@sync_method_callback('android', '页面操作', 1)
|
|
22
|
-
def a_swipe_right(self):
|
|
23
|
-
"""右滑"""
|
|
24
|
-
self.base_data.android.swipe_ext(Direction.HORIZ_FORWARD)
|
|
25
|
-
|
|
26
|
-
@sync_method_callback('android', '页面操作', 2)
|
|
27
|
-
def a_swipe_left(self):
|
|
28
|
-
"""左滑"""
|
|
29
|
-
self.base_data.android.swipe_ext(Direction.HORIZ_BACKWARD)
|
|
30
|
-
|
|
31
|
-
@sync_method_callback('android', '页面操作', 3)
|
|
32
|
-
def a_swipe_up(self):
|
|
33
|
-
"""上滑"""
|
|
34
|
-
self.base_data.android.swipe_ext(Direction.FORWARD)
|
|
35
|
-
|
|
36
|
-
@sync_method_callback('android', '页面操作', 4)
|
|
37
|
-
def a_swipe_down(self):
|
|
38
|
-
"""下滑"""
|
|
39
|
-
self.base_data.android.swipe_ext(Direction.BACKWARD)
|
|
40
|
-
|
|
41
|
-
@sync_method_callback('android', '页面操作', 5, [
|
|
42
|
-
MethodModel(n='当前x', f='sx', p='请输入sx坐标', d=True),
|
|
43
|
-
MethodModel(n='当前y', f='sy', p='请输入sy坐标', d=True),
|
|
44
|
-
MethodModel(n='目标x', f='ex', p='请输入ex坐标', d=True),
|
|
45
|
-
MethodModel(n='目标y', f='ey', p='请输入ey坐标', d=True)])
|
|
46
|
-
def a_swipe(self, sx, sy, ex, ey):
|
|
47
|
-
"""坐标滑动"""
|
|
48
|
-
self.base_data.android.swipe(sx, sy, ex, ey, 0.5)
|
|
49
|
-
|
|
50
|
-
@sync_method_callback('android', '页面操作', 6, [
|
|
51
|
-
MethodModel(n='当前x', f='sx', p='请输入sx坐标', d=True),
|
|
52
|
-
MethodModel(n='当前y', f='sy', p='请输入sy坐标', d=True),
|
|
53
|
-
MethodModel(n='目标x', f='ex', p='请输入ex坐标', d=True),
|
|
54
|
-
MethodModel(n='目标y', f='ey', p='请输入ey坐标', d=True)])
|
|
55
|
-
def a_drag(self, sx, sy, ex, ey):
|
|
56
|
-
"""坐标拖动"""
|
|
57
|
-
self.base_data.android.drag(sx, sy, ex, ey, 0.5)
|
|
58
|
-
|
|
59
|
-
@sync_method_callback('android', '页面操作', 7)
|
|
60
|
-
def a_open_quick_settings(self):
|
|
61
|
-
"""打开快速通知"""
|
|
62
|
-
self.base_data.android.open_quick_settings()
|
|
63
|
-
|
|
64
|
-
@sync_method_callback('android', '页面操作', 8, [
|
|
65
|
-
MethodModel(n='文件名称', f='file_name', p='请输入截图文件名称', d=True)])
|
|
66
|
-
def a_screenshot(self, file_name: str):
|
|
67
|
-
"""屏幕截图"""
|
|
68
|
-
self.base_data.android.screenshot(filename=os.path.join(self.base_data.screenshot_path, file_name))
|
|
69
|
-
|
|
70
|
-
@sync_method_callback('android', '页面操作', 9, [
|
|
71
|
-
MethodModel(n='x坐标', f='x', p='请输入按下的x坐标', d=True),
|
|
72
|
-
MethodModel(n='y坐标', f='y', p='请输入按下的x坐标', d=True),
|
|
73
|
-
MethodModel(n='长按时间', f='time_', p='请输入长按时间', d=True)])
|
|
74
|
-
def a_long_click(self, x, y, time_):
|
|
75
|
-
"""长按屏幕N秒"""
|
|
76
|
-
self.base_data.android.long_click(x, y, time_)
|
|
77
|
-
|
|
78
|
-
@sync_method_callback('android', '页面操作', 10)
|
|
79
|
-
def a_set_orientation_natural(self):
|
|
80
|
-
"""设置为natural"""
|
|
81
|
-
self.base_data.android.set_orientation("natural")
|
|
82
|
-
|
|
83
|
-
@sync_method_callback('android', '页面操作', 11)
|
|
84
|
-
def a_set_orientation_left(self):
|
|
85
|
-
"""设置为natural"""
|
|
86
|
-
self.base_data.android.set_orientation("left")
|
|
87
|
-
|
|
88
|
-
@sync_method_callback('android', '页面操作', 12)
|
|
89
|
-
def a_set_orientation_right(self):
|
|
90
|
-
"""设置为right"""
|
|
91
|
-
self.base_data.android.set_orientation("right")
|
|
92
|
-
|
|
93
|
-
@sync_method_callback('android', '页面操作', 13)
|
|
94
|
-
def a_set_orientation_upsidedown(self):
|
|
95
|
-
"""设置为upsidedown"""
|
|
96
|
-
self.base_data.android.set_orientation("upsidedown")
|
|
97
|
-
|
|
98
|
-
@sync_method_callback('android', '页面操作', 14)
|
|
99
|
-
def a_freeze_rotation(self):
|
|
100
|
-
"""冻结旋转"""
|
|
101
|
-
self.base_data.android.freeze_rotation()
|
|
102
|
-
|
|
103
|
-
@sync_method_callback('android', '页面操作', 15)
|
|
104
|
-
def a_freeze_rotation_false(self):
|
|
105
|
-
"""取消冻结旋转"""
|
|
106
|
-
self.base_data.android.freeze_rotation(False)
|
|
107
|
-
|
|
108
|
-
@sync_method_callback('android', '页面操作', 16)
|
|
109
|
-
def a_dump_hierarchy(self):
|
|
110
|
-
"""获取转储的内容"""
|
|
111
|
-
return self.base_data.android.dump_hierarchy()
|
|
112
|
-
|
|
113
|
-
@sync_method_callback('android', '页面操作', 17)
|
|
114
|
-
def a_open_notification(self):
|
|
115
|
-
"""打开通知"""
|
|
116
|
-
return self.base_data.android.dump_hierarchy()
|
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
# @Project: 芒果测试平台
|
|
3
|
-
# @Description:
|
|
4
|
-
# @Time : 2025-04-04 21:42
|
|
5
|
-
# @Author : 毛鹏
|
|
6
|
-
import re
|
|
7
|
-
import traceback
|
|
8
|
-
|
|
9
|
-
from playwright.async_api import Locator, Error, TimeoutError
|
|
10
|
-
|
|
11
|
-
from mangotools.assertion import MangoAssertion
|
|
12
|
-
from mangotools.enums import StatusEnum
|
|
13
|
-
from mangotools.mangos import Mango
|
|
14
|
-
from ....enums import ElementExpEnum, ElementOperationEnum
|
|
15
|
-
from ....exceptions import MangoAutomationError
|
|
16
|
-
from ....exceptions.error_msg import *
|
|
17
|
-
from ....uidrives._base_data import BaseData
|
|
18
|
-
from ....uidrives.web.async_web._assertion import AsyncWebAssertion
|
|
19
|
-
from ....uidrives.web.async_web._browser import AsyncWebBrowser
|
|
20
|
-
from ....uidrives.web.async_web._customization import AsyncWebCustomization
|
|
21
|
-
from ....uidrives.web.async_web._element import AsyncWebElement
|
|
22
|
-
from ....uidrives.web.async_web._input_device import AsyncWebDeviceInput
|
|
23
|
-
from ....uidrives.web.async_web._page import AsyncWebPage
|
|
24
|
-
|
|
25
|
-
re = re
|
|
26
|
-
__all__ = [
|
|
27
|
-
'AsyncWebPage',
|
|
28
|
-
'AsyncWebElement',
|
|
29
|
-
'AsyncWebDeviceInput',
|
|
30
|
-
'AsyncWebCustomization',
|
|
31
|
-
'AsyncWebBrowser',
|
|
32
|
-
'AsyncWebAssertion',
|
|
33
|
-
'AsyncWebDevice',
|
|
34
|
-
]
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
class AsyncWebDevice(AsyncWebBrowser,
|
|
38
|
-
AsyncWebPage,
|
|
39
|
-
AsyncWebElement,
|
|
40
|
-
AsyncWebDeviceInput,
|
|
41
|
-
AsyncWebCustomization):
|
|
42
|
-
|
|
43
|
-
def __init__(self, base_data: BaseData):
|
|
44
|
-
super().__init__(base_data)
|
|
45
|
-
|
|
46
|
-
async def open_url(self, is_open: bool = False):
|
|
47
|
-
if not self.base_data.is_open_url or is_open:
|
|
48
|
-
self.base_data.log.debug(f'打开url,is_open_url:{self.base_data.is_open_url},url:{self.base_data.url}')
|
|
49
|
-
await self.w_goto(self.base_data.url)
|
|
50
|
-
self.base_data.is_open_url = True
|
|
51
|
-
|
|
52
|
-
async def web_action_element(self, name, ope_key, ope_value, ):
|
|
53
|
-
self.base_data.log.debug(f'操作元素,名称:{name},key:{ope_key},value:{ope_value}')
|
|
54
|
-
try:
|
|
55
|
-
await Mango.a_e(self, ope_key, ope_value)
|
|
56
|
-
except TimeoutError as error:
|
|
57
|
-
self.base_data.log.debug(f'WEB自动化操作失败-1,类型:{type(error)},失败详情:{error}')
|
|
58
|
-
raise MangoAutomationError(*ERROR_MSG_0011, value=(name,))
|
|
59
|
-
except Error as error:
|
|
60
|
-
self.base_data.log.error(f'WEB自动化操作失败-2,类型:{type(error)},失败详情:{error}')
|
|
61
|
-
raise MangoAutomationError(*ERROR_MSG_0032, value=(name,))
|
|
62
|
-
except ValueError as error:
|
|
63
|
-
self.base_data.log.error(f'WEB自动化操作失败-3,类型:{type(error)},失败详情:{error}')
|
|
64
|
-
raise MangoAutomationError(*ERROR_MSG_0012)
|
|
65
|
-
|
|
66
|
-
async def web_assertion_element(self, name, ope_key, ope_value) -> str:
|
|
67
|
-
self.base_data.log.debug(f'断言元素,名称:{name},key:{ope_key},value:{ope_value}')
|
|
68
|
-
is_method = callable(getattr(AsyncWebAssertion, ope_key, None))
|
|
69
|
-
try:
|
|
70
|
-
if is_method:
|
|
71
|
-
if ope_value.get('actual', None) is None:
|
|
72
|
-
traceback.print_exc()
|
|
73
|
-
raise MangoAutomationError(*ERROR_MSG_0031, value=(name,))
|
|
74
|
-
self.base_data.log.debug(f'开始断言-1,方法:{ope_key},断言值:{ope_value}')
|
|
75
|
-
return await Mango.a_e(AsyncWebAssertion(self.base_data), ope_key, ope_value)
|
|
76
|
-
else:
|
|
77
|
-
self.base_data.log.debug(f'开始断言-2,方法:{ope_key},断言值:{ope_value}')
|
|
78
|
-
return MangoAssertion(self.base_data.mysql_connect, self.base_data.test_data) \
|
|
79
|
-
.ass(ope_key, ope_value.get('actual'), ope_value.get('expect'))
|
|
80
|
-
except AssertionError as error:
|
|
81
|
-
self.base_data.log.debug(f'WEB自动化断言失败-1,类型:{type(error)},失败详情:{error}')
|
|
82
|
-
raise MangoAutomationError(*ERROR_MSG_0017, value=error.args)
|
|
83
|
-
except AttributeError as error:
|
|
84
|
-
self.base_data.log.error(f'WEB自动化断言失败-2,类型:{type(error)},失败详情:{error}')
|
|
85
|
-
raise MangoAutomationError(*ERROR_MSG_0048)
|
|
86
|
-
except ValueError as error:
|
|
87
|
-
self.base_data.log.error(f'WEB自动化断言失败-3,类型:{type(error)},失败详情:{error}')
|
|
88
|
-
raise MangoAutomationError(*ERROR_MSG_0005)
|
|
89
|
-
|
|
90
|
-
except Error as error:
|
|
91
|
-
self.base_data.log.error(f'WEB自动化断言失败-4,类型:{type(error)},失败详情:{error}')
|
|
92
|
-
raise MangoAutomationError(*ERROR_MSG_0052, value=(name,), )
|
|
93
|
-
|
|
94
|
-
async def web_find_ele(self, name, _type, exp, loc, sub, is_iframe) \
|
|
95
|
-
-> tuple[Locator, int, str] | tuple[list[Locator], int, str]:
|
|
96
|
-
self.base_data.log.debug(
|
|
97
|
-
f'查找元素,名称:{name},_type:{_type},exp:{exp},loc:{loc},sub:{sub},is_iframe:{is_iframe}')
|
|
98
|
-
if is_iframe != StatusEnum.SUCCESS.value:
|
|
99
|
-
locator: Locator = await self.__find_ele(self.base_data.page, exp, loc)
|
|
100
|
-
try:
|
|
101
|
-
count = await locator.count()
|
|
102
|
-
loc = locator.nth(sub - 1) if sub else locator
|
|
103
|
-
try:
|
|
104
|
-
text = await self.w_get_text(loc)
|
|
105
|
-
except Exception:
|
|
106
|
-
text = None
|
|
107
|
-
return loc, count, text
|
|
108
|
-
except Error as error:
|
|
109
|
-
self.base_data.log.debug(
|
|
110
|
-
f'WEB自动化查找元素失败-1,类型:{type(error)},失败详情:{error},失败明细:{traceback.format_exc()}')
|
|
111
|
-
raise MangoAutomationError(*ERROR_MSG_0041, value=(name, loc))
|
|
112
|
-
else:
|
|
113
|
-
ele_list: list[Locator] = []
|
|
114
|
-
for i in self.base_data.page.frames:
|
|
115
|
-
locator: Locator = await self.__find_ele(i, exp, loc)
|
|
116
|
-
try:
|
|
117
|
-
count = await locator.count()
|
|
118
|
-
except Error as error:
|
|
119
|
-
self.base_data.log.debug(
|
|
120
|
-
f'WEB自动化查找元素失败-2,类型:{type(error)},失败详情:{error},失败明细:{traceback.format_exc()}')
|
|
121
|
-
raise MangoAutomationError(*ERROR_MSG_0041, )
|
|
122
|
-
if count > 0:
|
|
123
|
-
for nth in range(0, count):
|
|
124
|
-
ele_list.append(locator.nth(nth))
|
|
125
|
-
else:
|
|
126
|
-
raise MangoAutomationError(*ERROR_MSG_0023)
|
|
127
|
-
if not ele_list:
|
|
128
|
-
raise MangoAutomationError(*ERROR_MSG_0023)
|
|
129
|
-
if not ele_list and _type == ElementOperationEnum.OPE:
|
|
130
|
-
raise MangoAutomationError(*ERROR_MSG_0029, value=(name, loc))
|
|
131
|
-
try:
|
|
132
|
-
count = len(ele_list)
|
|
133
|
-
loc = ele_list[sub - 1] if sub else ele_list
|
|
134
|
-
try:
|
|
135
|
-
text = await self.w_get_text(loc)
|
|
136
|
-
except Exception:
|
|
137
|
-
text = None
|
|
138
|
-
return loc, count, text
|
|
139
|
-
except IndexError:
|
|
140
|
-
raise MangoAutomationError(*ERROR_MSG_0025, value=(len(ele_list),))
|
|
141
|
-
|
|
142
|
-
async def __find_ele(self, page, exp, loc) -> Locator:
|
|
143
|
-
match exp:
|
|
144
|
-
case ElementExpEnum.LOCATOR.value:
|
|
145
|
-
try:
|
|
146
|
-
return eval(f"await page.{loc}")
|
|
147
|
-
except SyntaxError:
|
|
148
|
-
try:
|
|
149
|
-
return eval(f"page.{loc}")
|
|
150
|
-
except SyntaxError as error:
|
|
151
|
-
self.base_data.log.error(f'WEB自动化查找元素失败-3,类型:{type(error)},失败详情:{error}')
|
|
152
|
-
raise MangoAutomationError(*ERROR_MSG_0022)
|
|
153
|
-
except NameError as error:
|
|
154
|
-
self.base_data.log.error(f'WEB自动化查找元素失败-4,类型:{type(error)},失败详情:{error}')
|
|
155
|
-
raise MangoAutomationError(*ERROR_MSG_0060)
|
|
156
|
-
case ElementExpEnum.XPATH.value:
|
|
157
|
-
return page.locator(f'xpath={loc}')
|
|
158
|
-
case ElementExpEnum.CSS.value:
|
|
159
|
-
return page.locator(loc)
|
|
160
|
-
case ElementExpEnum.TEXT.value:
|
|
161
|
-
return page.get_by_text(loc, exact=True)
|
|
162
|
-
case ElementExpEnum.PLACEHOLDER.value:
|
|
163
|
-
return page.get_by_placeholder(loc)
|
|
164
|
-
case _:
|
|
165
|
-
raise MangoAutomationError(*ERROR_MSG_0020)
|