mangoautomation 1.1.23__py3-none-any.whl → 1.1.25__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.25.dist-info/METADATA +42 -0
- mangoautomation-1.1.25.dist-info/RECORD +48 -0
- {mangoautomation-1.1.23.dist-info → mangoautomation-1.1.25.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.25.dist-info/licenses}/LICENSE +0 -0
- {mangoautomation-1.1.23.dist-info → mangoautomation-1.1.25.dist-info}/top_level.txt +0 -0
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
# @Project: 芒果测试平台
|
|
3
|
-
# @Description: # @Time : 2023-04-29 12:11
|
|
4
|
-
# @Author : 毛鹏
|
|
5
|
-
|
|
6
|
-
from mangotools.decorator import async_method_callback
|
|
7
|
-
from mangotools.models import MethodModel
|
|
8
|
-
from ....tools import Meta
|
|
9
|
-
from ....uidrives._base_data import BaseData
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
class AsyncWebDeviceInput(metaclass=Meta):
|
|
13
|
-
"""输入设备"""
|
|
14
|
-
|
|
15
|
-
def __init__(self, base_data: BaseData):
|
|
16
|
-
self.base_data = base_data
|
|
17
|
-
|
|
18
|
-
@async_method_callback('web', '输入设备', 0, [
|
|
19
|
-
MethodModel(n='按键值', f='keyboard', p='请输入键盘名称,首字母大写', d=True)])
|
|
20
|
-
async def w_keys(self, keyboard: str):
|
|
21
|
-
"""模拟按下指定的键"""
|
|
22
|
-
await self.base_data.page.keyboard.press(str(keyboard))
|
|
23
|
-
|
|
24
|
-
@async_method_callback('web', '输入设备', 1, [
|
|
25
|
-
MethodModel(n='滚动像素', f='y', p='请输入向上滚动像素', d=True)])
|
|
26
|
-
async def w_wheel(self, y):
|
|
27
|
-
"""鼠标上下滚动像素,负数代表向上"""
|
|
28
|
-
await self.base_data.page.mouse.wheel(0, int(y))
|
|
29
|
-
|
|
30
|
-
@async_method_callback('web', '输入设备', 2, [
|
|
31
|
-
MethodModel(n='x坐标', f='x', p='请输入点击的x轴', d=True),
|
|
32
|
-
MethodModel(n='y坐标', f='y', p='请输入点击的y轴', d=True)])
|
|
33
|
-
async def w_mouse_click(self, x: float, y: float):
|
|
34
|
-
"""鼠标点击坐标"""
|
|
35
|
-
await self.base_data.page.mouse.click(float(x), float(y))
|
|
36
|
-
|
|
37
|
-
@async_method_callback('web', '输入设备', 3)
|
|
38
|
-
async def w_mouse_center(self):
|
|
39
|
-
"""鼠标移动到中间"""
|
|
40
|
-
|
|
41
|
-
viewport_size = await self.base_data.page.evaluate('''() => {
|
|
42
|
-
return {
|
|
43
|
-
width: window.innerWidth,
|
|
44
|
-
height: window.innerHeight
|
|
45
|
-
}
|
|
46
|
-
}''')
|
|
47
|
-
center_x = viewport_size['width'] / 2
|
|
48
|
-
center_y = viewport_size['height'] / 2
|
|
49
|
-
await self.base_data.page.mouse.move(center_x, center_y)
|
|
50
|
-
|
|
51
|
-
@async_method_callback('web', '输入设备', 4)
|
|
52
|
-
async def w_mouse_center(self):
|
|
53
|
-
"""鼠标移动到中间并点击"""
|
|
54
|
-
|
|
55
|
-
viewport_size = await self.base_data.page.evaluate('''() => {
|
|
56
|
-
return {
|
|
57
|
-
width: window.innerWidth,
|
|
58
|
-
height: window.innerHeight
|
|
59
|
-
}
|
|
60
|
-
}''')
|
|
61
|
-
center_x = viewport_size['width'] / 2
|
|
62
|
-
center_y = viewport_size['height'] / 2
|
|
63
|
-
await self.base_data.page.mouse.click(center_x, center_y)
|
|
64
|
-
|
|
65
|
-
@async_method_callback('web', '输入设备', 5, [
|
|
66
|
-
MethodModel(n='输入文本', f='text', p='请输入键盘输入的内容', d=True)])
|
|
67
|
-
async def w_keyboard_type_text(self, text: str):
|
|
68
|
-
"""模拟人工输入文字"""
|
|
69
|
-
await self.base_data.page.keyboard.type(str(text))
|
|
70
|
-
|
|
71
|
-
@async_method_callback('web', '输入设备', 6, [
|
|
72
|
-
MethodModel(n='输入文本', f='text', p='请输入键盘输入的内容', d=True)])
|
|
73
|
-
async def w_keyboard_insert_text(self, text: str):
|
|
74
|
-
"""直接输入文字"""
|
|
75
|
-
await self.base_data.page.keyboard.insert_text(str(text))
|
|
76
|
-
|
|
77
|
-
@async_method_callback('web', '输入设备', 7, [
|
|
78
|
-
MethodModel(n='删除个数', f='count', p='请输入要删除字符串的个数', d=True)])
|
|
79
|
-
async def w_keyboard_delete_text(self, count: int):
|
|
80
|
-
"""删除光标左侧的字符"""
|
|
81
|
-
for _ in range(0, int(count) + 1):
|
|
82
|
-
await self.base_data.page.keyboard.press("Backspace")
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
# @Project: 芒果测试平台
|
|
3
|
-
# @Description:
|
|
4
|
-
# @Time : 2024-04-24 10:43
|
|
5
|
-
# @Author : 毛鹏
|
|
6
|
-
import asyncio
|
|
7
|
-
import ctypes
|
|
8
|
-
import os
|
|
9
|
-
import string
|
|
10
|
-
import traceback
|
|
11
|
-
from typing import Optional
|
|
12
|
-
|
|
13
|
-
from playwright._impl._errors import Error
|
|
14
|
-
from playwright.async_api import async_playwright, Page, BrowserContext, Browser, Playwright, Request, Route
|
|
15
|
-
|
|
16
|
-
from ....enums import BrowserTypeEnum
|
|
17
|
-
from ....exceptions import MangoAutomationError
|
|
18
|
-
from ....exceptions.error_msg import ERROR_MSG_0057, ERROR_MSG_0008, ERROR_MSG_0062, ERROR_MSG_0009, ERROR_MSG_0055
|
|
19
|
-
|
|
20
|
-
"""
|
|
21
|
-
python -m uiautomator2 init
|
|
22
|
-
python -m weditor
|
|
23
|
-
|
|
24
|
-
"""
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
class AsyncWebNewBrowser:
|
|
28
|
-
|
|
29
|
-
def __init__(self,
|
|
30
|
-
web_type: int,
|
|
31
|
-
web_path: str | None = None,
|
|
32
|
-
web_max=False,
|
|
33
|
-
web_headers=False,
|
|
34
|
-
web_recording=False,
|
|
35
|
-
web_h5=None,
|
|
36
|
-
is_header_intercept=False,
|
|
37
|
-
web_is_default=False,
|
|
38
|
-
videos_path=None,
|
|
39
|
-
log=None,
|
|
40
|
-
):
|
|
41
|
-
self.lock = asyncio.Lock()
|
|
42
|
-
self.web_type = web_type
|
|
43
|
-
self.web_path = web_path
|
|
44
|
-
self.web_max = web_max
|
|
45
|
-
self.web_headers = web_headers
|
|
46
|
-
self.web_recording = web_recording
|
|
47
|
-
self.web_h5 = web_h5
|
|
48
|
-
self.web_is_default = web_is_default
|
|
49
|
-
self.is_header_intercept = is_header_intercept
|
|
50
|
-
self.videos_path = videos_path
|
|
51
|
-
self.log = log
|
|
52
|
-
self.browser_path = ['chrome.exe', 'msedge.exe', 'firefox.exe', '苹果', '360se.exe']
|
|
53
|
-
self.browser: Optional[None | Browser] = None
|
|
54
|
-
self.playwright: Optional[None | Playwright] = None
|
|
55
|
-
|
|
56
|
-
async def new_web_page(self, count=0) -> tuple[BrowserContext, Page]:
|
|
57
|
-
if self.browser is None:
|
|
58
|
-
async with self.lock:
|
|
59
|
-
if self.browser is None:
|
|
60
|
-
self.browser = await self.new_browser()
|
|
61
|
-
await asyncio.sleep(1)
|
|
62
|
-
try:
|
|
63
|
-
context = await self.new_context()
|
|
64
|
-
page = await self.new_page(context)
|
|
65
|
-
return context, page
|
|
66
|
-
except Exception:
|
|
67
|
-
self.log.error(f'初始化page失败,错误信息:{traceback.format_exc()}')
|
|
68
|
-
self.browser = None
|
|
69
|
-
if count >= 3:
|
|
70
|
-
raise MangoAutomationError(*ERROR_MSG_0057)
|
|
71
|
-
else:
|
|
72
|
-
return await self.new_web_page(count=count + 1)
|
|
73
|
-
|
|
74
|
-
async def new_browser(self) -> Browser:
|
|
75
|
-
self.playwright = await async_playwright().start()
|
|
76
|
-
if self.web_type == BrowserTypeEnum.CHROMIUM.value or self.web_type == BrowserTypeEnum.EDGE.value:
|
|
77
|
-
browser = self.playwright.chromium
|
|
78
|
-
elif self.web_type == BrowserTypeEnum.FIREFOX.value:
|
|
79
|
-
browser = self.playwright.firefox
|
|
80
|
-
elif self.web_type == BrowserTypeEnum.WEBKIT.value:
|
|
81
|
-
browser = self.playwright.webkit
|
|
82
|
-
else:
|
|
83
|
-
raise MangoAutomationError(*ERROR_MSG_0008)
|
|
84
|
-
if self.web_is_default:
|
|
85
|
-
try:
|
|
86
|
-
return await browser.launch()
|
|
87
|
-
except Error as error:
|
|
88
|
-
self.log.error(f'初始化浏览器失败-1,类型:{error},详情:{traceback.format_exc()}')
|
|
89
|
-
raise MangoAutomationError(*ERROR_MSG_0062)
|
|
90
|
-
else:
|
|
91
|
-
try:
|
|
92
|
-
if self.web_max:
|
|
93
|
-
return await browser.launch(
|
|
94
|
-
headless=self.web_headers,
|
|
95
|
-
executable_path=self.web_path if self.web_path else self.__search_path(),
|
|
96
|
-
args=['--start-maximized']
|
|
97
|
-
)
|
|
98
|
-
else:
|
|
99
|
-
return await browser.launch(
|
|
100
|
-
headless=self.web_headers,
|
|
101
|
-
executable_path=self.web_path if self.web_path else self.__search_path()
|
|
102
|
-
)
|
|
103
|
-
except Error as error:
|
|
104
|
-
self.log.error(f'初始化浏览器失败-2,类型:{error},详情:{traceback.format_exc()}')
|
|
105
|
-
raise MangoAutomationError(*ERROR_MSG_0009, value=(self.web_path,))
|
|
106
|
-
|
|
107
|
-
async def new_context(self) -> BrowserContext:
|
|
108
|
-
args_dict = {'ignore_https_errors': True}
|
|
109
|
-
if self.web_is_default:
|
|
110
|
-
args_dict["viewport"] = {"width": 1920, "height": 1080}
|
|
111
|
-
if self.web_h5:
|
|
112
|
-
args_dict.update(self.playwright.devices[self.web_h5])
|
|
113
|
-
if not (self.web_is_default or self.web_h5):
|
|
114
|
-
args_dict["no_viewport"] = True
|
|
115
|
-
if self.web_recording and self.videos_path:
|
|
116
|
-
args_dict["record_video_dir"] = self.videos_path
|
|
117
|
-
context = await self.browser.new_context(**args_dict)
|
|
118
|
-
context.set_default_timeout(3000)
|
|
119
|
-
return context
|
|
120
|
-
|
|
121
|
-
async def new_page(self, context: BrowserContext) -> Page:
|
|
122
|
-
try:
|
|
123
|
-
page = await context.new_page()
|
|
124
|
-
page.set_default_timeout(3000)
|
|
125
|
-
if self.is_header_intercept:
|
|
126
|
-
await page.route("**/*", self.wen_intercept_request) # 应用拦截函数到页面的所有请求
|
|
127
|
-
return page
|
|
128
|
-
except Error as error:
|
|
129
|
-
self.log.error(f'初始化page失败,类型:{error},详情:{traceback.format_exc()}')
|
|
130
|
-
raise MangoAutomationError(*ERROR_MSG_0009, value=(self.web_path,))
|
|
131
|
-
|
|
132
|
-
async def close(self):
|
|
133
|
-
if self.browser:
|
|
134
|
-
await self.browser.close()
|
|
135
|
-
|
|
136
|
-
def __search_path(self, ):
|
|
137
|
-
drives = []
|
|
138
|
-
for letter in string.ascii_uppercase:
|
|
139
|
-
drive = f"{letter}:\\"
|
|
140
|
-
if ctypes.windll.kernel32.GetDriveTypeW(drive) == 3:
|
|
141
|
-
drives.append(drive)
|
|
142
|
-
for i in drives:
|
|
143
|
-
for root, dirs, files in os.walk(i):
|
|
144
|
-
if self.browser_path[self.web_type] in files:
|
|
145
|
-
return os.path.join(root, self.browser_path[self.web_type])
|
|
146
|
-
|
|
147
|
-
raise MangoAutomationError(*ERROR_MSG_0055)
|
|
148
|
-
|
|
149
|
-
async def wen_intercept_request(self, route: Route, request: Request):
|
|
150
|
-
pass
|
|
151
|
-
|
|
152
|
-
async def wen_recording_api(self, request: Request, project_product: int):
|
|
153
|
-
pass
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
# -*- coding: utf-8 -*-
|
|
2
|
-
# @Project: 芒果测试平台
|
|
3
|
-
# @Description: # @Time : 2023-04-25 22:33
|
|
4
|
-
# @Author : 毛鹏
|
|
5
|
-
import asyncio
|
|
6
|
-
|
|
7
|
-
from playwright.async_api import Locator
|
|
8
|
-
|
|
9
|
-
from mangotools.decorator import async_method_callback
|
|
10
|
-
from mangotools.models import MethodModel
|
|
11
|
-
from ....tools import Meta
|
|
12
|
-
from ....uidrives._base_data import BaseData
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
class AsyncWebPage(metaclass=Meta):
|
|
16
|
-
"""页面操作"""
|
|
17
|
-
|
|
18
|
-
def __init__(self, base_data: BaseData):
|
|
19
|
-
self.base_data = base_data
|
|
20
|
-
|
|
21
|
-
@async_method_callback('web', '页面操作', 0, [
|
|
22
|
-
MethodModel(n='页签下标', f='individual', p='请输入页签下标,从1开始数', d=True)])
|
|
23
|
-
async def w_switch_tabs(self, individual: int):
|
|
24
|
-
"""切换页签"""
|
|
25
|
-
pages = self.base_data.context.pages
|
|
26
|
-
await pages[int(individual) + 1].bring_to_front()
|
|
27
|
-
self.base_data.page = pages[int(individual) + 1]
|
|
28
|
-
await asyncio.sleep(1)
|
|
29
|
-
|
|
30
|
-
@async_method_callback('web', '页面操作', 1)
|
|
31
|
-
async def w_close_current_tab(self):
|
|
32
|
-
"""关闭当前页签"""
|
|
33
|
-
await asyncio.sleep(2)
|
|
34
|
-
pages = self.base_data.context.pages
|
|
35
|
-
await pages[-1].close()
|
|
36
|
-
self.base_data.page = pages[0]
|
|
37
|
-
|
|
38
|
-
@async_method_callback('web', '页面操作', 2, [MethodModel(f='locating')])
|
|
39
|
-
async def w_open_new_tab_and_switch(self, locating: Locator):
|
|
40
|
-
"""点击并打开新页签"""
|
|
41
|
-
|
|
42
|
-
await locating.click()
|
|
43
|
-
await asyncio.sleep(2)
|
|
44
|
-
pages = self.base_data.context.pages
|
|
45
|
-
new_page = pages[-1]
|
|
46
|
-
await new_page.bring_to_front()
|
|
47
|
-
self.base_data.page = new_page
|
|
48
|
-
await asyncio.sleep(1)
|
|
49
|
-
|
|
50
|
-
@async_method_callback('web', '页面操作', 3)
|
|
51
|
-
async def w_refresh(self):
|
|
52
|
-
"""刷新页面"""
|
|
53
|
-
await self.base_data.page.reload()
|
|
54
|
-
|
|
55
|
-
@async_method_callback('web', '页面操作', 4)
|
|
56
|
-
async def w_go_back(self):
|
|
57
|
-
"""返回上一页"""
|
|
58
|
-
await self.base_data.page.go_back()
|
|
59
|
-
|
|
60
|
-
@async_method_callback('web', '页面操作', 5)
|
|
61
|
-
async def w_go_forward(self):
|
|
62
|
-
"""前进到下一页"""
|
|
63
|
-
await self.base_data.page.go_forward()
|
|
@@ -1,160 +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.sync_api import Locator, TimeoutError, Error
|
|
10
|
-
|
|
11
|
-
from mangotools.assertion import MangoAssertion
|
|
12
|
-
from mangotools.enums import StatusEnum
|
|
13
|
-
from mangotools.mangos import Mango
|
|
14
|
-
from ....enums import ElementExpEnum
|
|
15
|
-
from ....exceptions import MangoAutomationError
|
|
16
|
-
from ....exceptions.error_msg import *
|
|
17
|
-
from ....uidrives._base_data import BaseData
|
|
18
|
-
from ....uidrives.web.sync_web._assertion import SyncWebAssertion
|
|
19
|
-
from ....uidrives.web.sync_web._browser import SyncWebBrowser
|
|
20
|
-
from ....uidrives.web.sync_web._customization import SyncWebCustomization
|
|
21
|
-
from ....uidrives.web.sync_web._element import SyncWebElement
|
|
22
|
-
from ....uidrives.web.sync_web._input_device import SyncWebDeviceInput
|
|
23
|
-
from ....uidrives.web.sync_web._page import SyncWebPage
|
|
24
|
-
|
|
25
|
-
re = re
|
|
26
|
-
__all__ = [
|
|
27
|
-
'SyncWebAssertion',
|
|
28
|
-
'SyncWebBrowser',
|
|
29
|
-
'SyncWebCustomization',
|
|
30
|
-
'SyncWebDeviceInput',
|
|
31
|
-
'SyncWebElement',
|
|
32
|
-
'SyncWebPage',
|
|
33
|
-
'SyncWebDevice',
|
|
34
|
-
]
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
class SyncWebDevice(SyncWebBrowser,
|
|
38
|
-
SyncWebPage,
|
|
39
|
-
SyncWebElement,
|
|
40
|
-
SyncWebDeviceInput,
|
|
41
|
-
SyncWebCustomization):
|
|
42
|
-
|
|
43
|
-
def __init__(self, base_data: BaseData):
|
|
44
|
-
super().__init__(base_data)
|
|
45
|
-
|
|
46
|
-
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
|
-
self.w_goto(self.base_data.url)
|
|
50
|
-
self.base_data.is_open_url = True
|
|
51
|
-
|
|
52
|
-
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
|
-
Mango.s_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
|
-
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(SyncWebAssertion, ope_key, None))
|
|
69
|
-
try:
|
|
70
|
-
if is_method:
|
|
71
|
-
if ope_value.get('actual', None) is None:
|
|
72
|
-
raise MangoAutomationError(*ERROR_MSG_0031, value=(name,))
|
|
73
|
-
self.base_data.log.debug(f'开始断言-1,方法:{ope_key},断言值:{ope_value}')
|
|
74
|
-
return Mango.s_e(SyncWebAssertion(self.base_data), ope_key, ope_value)
|
|
75
|
-
else:
|
|
76
|
-
self.base_data.log.debug(f'开始断言-2,方法:{ope_key},断言值:{ope_value}')
|
|
77
|
-
return MangoAssertion(self.base_data.mysql_connect, self.base_data.test_data) \
|
|
78
|
-
.ass(ope_key, ope_value.get('actual'), ope_value.get('expect'))
|
|
79
|
-
except AssertionError as error:
|
|
80
|
-
self.base_data.log.debug(f'WEB自动化断言失败-1,类型:{type(error)},失败详情:{error}')
|
|
81
|
-
raise MangoAutomationError(*ERROR_MSG_0017, value=error.args)
|
|
82
|
-
except AttributeError as error:
|
|
83
|
-
self.base_data.log.error(f'WEB自动化断言失败-2,类型:{type(error)},失败详情:{error}')
|
|
84
|
-
raise MangoAutomationError(*ERROR_MSG_0048)
|
|
85
|
-
except ValueError as error:
|
|
86
|
-
self.base_data.log.error(f'WEB自动化断言失败-3,类型:{type(error)},失败详情:{error}')
|
|
87
|
-
raise MangoAutomationError(*ERROR_MSG_0005)
|
|
88
|
-
except Error as error:
|
|
89
|
-
self.base_data.log.error(f'WEB自动化断言失败-4,类型:{type(error)},失败详情:{error}')
|
|
90
|
-
raise MangoAutomationError(*ERROR_MSG_0052, value=(name,), )
|
|
91
|
-
|
|
92
|
-
def web_find_ele(self, name, _type, exp, loc, sub, is_iframe) \
|
|
93
|
-
-> tuple[Locator, int, str] | tuple[list[Locator], int, str]:
|
|
94
|
-
self.base_data.log.debug(
|
|
95
|
-
f'查找元素,名称:{name},_type:{_type},exp:{exp},loc:{loc},sub:{sub},is_iframe:{is_iframe}')
|
|
96
|
-
if is_iframe != StatusEnum.SUCCESS.value:
|
|
97
|
-
locator: Locator = self.__find_ele(self.base_data.page, exp, loc)
|
|
98
|
-
try:
|
|
99
|
-
count = locator.count()
|
|
100
|
-
loc = locator.nth(sub - 1) if sub else locator
|
|
101
|
-
try:
|
|
102
|
-
text = self.w_get_text(loc)
|
|
103
|
-
except Exception:
|
|
104
|
-
text = None
|
|
105
|
-
return loc, count, text
|
|
106
|
-
except Error as error:
|
|
107
|
-
self.base_data.log.debug(
|
|
108
|
-
f'WEB自动化查找元素失败-1,类型:{type(error)},失败详情:{error},失败明细:{traceback.format_exc()}')
|
|
109
|
-
raise MangoAutomationError(*ERROR_MSG_0041, )
|
|
110
|
-
else:
|
|
111
|
-
ele_list: list[Locator] = []
|
|
112
|
-
for i in self.base_data.page.frames:
|
|
113
|
-
locator: Locator = self.__find_ele(i, exp, loc)
|
|
114
|
-
try:
|
|
115
|
-
count = locator.count()
|
|
116
|
-
except Error as error:
|
|
117
|
-
self.base_data.log.debug(
|
|
118
|
-
f'WEB自动化查找元素失败-2,类型:{type(error)},失败详情:{error},失败明细:{traceback.format_exc()}')
|
|
119
|
-
raise MangoAutomationError(*ERROR_MSG_0041, )
|
|
120
|
-
if count > 0:
|
|
121
|
-
for nth in range(0, count):
|
|
122
|
-
ele_list.append(locator.nth(nth))
|
|
123
|
-
else:
|
|
124
|
-
raise MangoAutomationError(*ERROR_MSG_0023)
|
|
125
|
-
|
|
126
|
-
try:
|
|
127
|
-
count = len(ele_list)
|
|
128
|
-
loc = ele_list[sub - 1] if sub else ele_list[0]
|
|
129
|
-
try:
|
|
130
|
-
text = self.w_get_text(loc)
|
|
131
|
-
except Exception:
|
|
132
|
-
text = None
|
|
133
|
-
return loc, count, text
|
|
134
|
-
except IndexError:
|
|
135
|
-
raise MangoAutomationError(*ERROR_MSG_0025, value=(len(ele_list),))
|
|
136
|
-
|
|
137
|
-
def __find_ele(self, page, exp, loc) -> Locator:
|
|
138
|
-
match exp:
|
|
139
|
-
case ElementExpEnum.LOCATOR.value:
|
|
140
|
-
try:
|
|
141
|
-
return eval(f"page.{loc}")
|
|
142
|
-
except SyntaxError:
|
|
143
|
-
try:
|
|
144
|
-
return eval(f"await page.{loc}")
|
|
145
|
-
except SyntaxError as error:
|
|
146
|
-
self.base_data.log.error(f'WEB自动化查找元素失败-3,类型:{type(error)},失败详情:{error}')
|
|
147
|
-
raise MangoAutomationError(*ERROR_MSG_0022)
|
|
148
|
-
except NameError as error:
|
|
149
|
-
self.base_data.log.error(f'WEB自动化查找元素失败-4,类型:{type(error)},失败详情:{error}')
|
|
150
|
-
raise MangoAutomationError(*ERROR_MSG_0060)
|
|
151
|
-
case ElementExpEnum.XPATH.value:
|
|
152
|
-
return page.locator(f'xpath={loc}')
|
|
153
|
-
case ElementExpEnum.CSS.value:
|
|
154
|
-
return page.locator(loc)
|
|
155
|
-
case ElementExpEnum.TEXT.value:
|
|
156
|
-
return page.get_by_text(loc, exact=True)
|
|
157
|
-
case ElementExpEnum.PLACEHOLDER.value:
|
|
158
|
-
return page.get_by_placeholder(loc)
|
|
159
|
-
case _:
|
|
160
|
-
raise MangoAutomationError(*ERROR_MSG_0020)
|