Selenium:Web前端
不适用于WebView程序
官方文档:https://www.selenium.dev/documentation/
项目源码:https://github.com/SeleniumHQ/selenium
创建实例化对象,加载浏览器驱动程序
Edge驱动下载地址:https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/
Chrom驱动下载地址:https://chromedriver.storage.googleapis.com/index.html
调用驱动,打开URL
编写测试用例操作,最好封装成函数
Edge浏览器获取元素XPath定位:
find_element(By.XPATH, value = )
Unittest测试框架:
统计测试时间,编写测试断言
用例函数名定义规范,不规范的不能识别为用例:
def test_用例名
执行用例操作并且恢复环境
第一步:准备用例数据(需要输入的字符串文本)
第二步:执行页面操作
第三步:使用断言Assert比对预期结果和实际结果
BeautifulReport生成HTML格式的测试报告
第一步:创建一个测试套件(相当于用例的集合)
第二步:加载用例到套件
第三步:执行套件中的用例,生成测试报告
查看测试结果,异常操作调试信息定位到行
执行用例失败的两种情况:
不适用于HTML模板
PyWinAuto官方文档https://pywinauto.readthedocs.io/en/latest/
PyWinAuto项目源码https://github.com/pywinauto/pywinauto
[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-umVHT3ae-1688439866846)(C:\Users\Dell\AppData\Roaming\Typora\typora-user-images\image-20230613141143707.png)]
print_control_identifiers()
打印控件结构,按路径层级访问
可视控件的访问方法
(1)使用.通用方法(推荐使用)
(2)使用.[“”],适用于中文名称
(3)使用child_window方法
click()和click_input():
click()不移动鼠标
click_input()移动鼠标到目标元素上面
经常使用main_dlg.print_control_identifiers()
打印主窗口的控件结构
常见控件:
英文名称 | 中文名称 | |
---|---|---|
TabControlWrapper | TabControl | 选项卡 |
TreeViewWrapper | TreeView | 树视图 |
ListViewWrapper | ListView | 列表视图 |
ComboBoxWrapper | ComboBox | 组合框(下拉菜单) |
EditWrapper | Edit | 文本框 |
ButtonWrapper | Button, CheckBox, RadioButton, GroupBox,MinimizeButton,RestoreButton,CloseButton | 按钮 |
StaticWrapper | Static | 静态文本 |
ToolbarWrapper | Toolbar | 工具栏 |
DialogWrapper | Dialog | 对话 |
StatusBarWrapper | StatusBar | 状态栏 |
常用方法
- capture_as_image
- click
- click_input
- close
- close_click
- debug_message
- double_click
- double_click_input
- drag_mouse
- draw_outline
- get_focus
- get_show_state
- maximize
- menu_select
- minimize
- move_mouse
- move_window
- notify_menu_select
- notify_parent
- press_mouse
- press_mouse_input
- release_mouse
- release_mouse_input
- restore
- right_click
- right_click_input
- send_message
- send_message_timeout
- set_focus
- set_window_text
- type_keys
- Children
- Class
- ClientRect
- ClientRects
- ContextHelpID
- ControlID
- ExStyle
- Font
- Fonts
- FriendlyClassName
- GetProperties
- HasExStyle
- HasStyle
- IsChild
- IsDialog
- IsEnabled
- IsUnicode
- IsVisible
- Menu
- MenuItem
- MenuItems
- Owner
- Parent
- PopupWindow
- ProcessID
- Rectangle
- Style
- Texts
- TopLevelParent
- UserData
- VerifyActionable
- VerifyEnabled
- VerifyVisible
- WindowText
打开新窗口,重新排序,类似Web前端网页资源重定向
兼容处理:0和1都是第一个
文件流重定向
需要使用管理员权限打开IDE(PyCharm)或者编译时赋予管理员权限
Squnish:Qt跨平台应用