pytest-dsl-ui 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.
Files changed (35) hide show
  1. pytest_dsl_ui-0.1.0/PKG-INFO +220 -0
  2. pytest_dsl_ui-0.1.0/README.md +192 -0
  3. pytest_dsl_ui-0.1.0/pyproject.toml +59 -0
  4. pytest_dsl_ui-0.1.0/pytest_dsl_ui/__init__.py +39 -0
  5. pytest_dsl_ui-0.1.0/pytest_dsl_ui/__main__.py +106 -0
  6. pytest_dsl_ui-0.1.0/pytest_dsl_ui/core/__init__.py +1 -0
  7. pytest_dsl_ui-0.1.0/pytest_dsl_ui/core/auth_manager.py +248 -0
  8. pytest_dsl_ui-0.1.0/pytest_dsl_ui/core/browser_manager.py +261 -0
  9. pytest_dsl_ui-0.1.0/pytest_dsl_ui/core/element_locator.py +844 -0
  10. pytest_dsl_ui-0.1.0/pytest_dsl_ui/core/element_locator_improved.py +619 -0
  11. pytest_dsl_ui-0.1.0/pytest_dsl_ui/core/page_context.py +225 -0
  12. pytest_dsl_ui-0.1.0/pytest_dsl_ui/examples/test_compound_locator.py +99 -0
  13. pytest_dsl_ui-0.1.0/pytest_dsl_ui/examples/test_converted_locators.py +126 -0
  14. pytest_dsl_ui-0.1.0/pytest_dsl_ui/examples/test_locator.py +33 -0
  15. pytest_dsl_ui-0.1.0/pytest_dsl_ui/keywords/__init__.py +27 -0
  16. pytest_dsl_ui-0.1.0/pytest_dsl_ui/keywords/assertion_keywords.py +1558 -0
  17. pytest_dsl_ui-0.1.0/pytest_dsl_ui/keywords/auth_keywords.py +695 -0
  18. pytest_dsl_ui-0.1.0/pytest_dsl_ui/keywords/browser_keywords.py +417 -0
  19. pytest_dsl_ui-0.1.0/pytest_dsl_ui/keywords/captcha_keywords.py +245 -0
  20. pytest_dsl_ui-0.1.0/pytest_dsl_ui/keywords/capture_keywords.py +419 -0
  21. pytest_dsl_ui-0.1.0/pytest_dsl_ui/keywords/element_keywords.py +364 -0
  22. pytest_dsl_ui-0.1.0/pytest_dsl_ui/keywords/element_keywords_extended.py +396 -0
  23. pytest_dsl_ui-0.1.0/pytest_dsl_ui/keywords/navigation_keywords.py +351 -0
  24. pytest_dsl_ui-0.1.0/pytest_dsl_ui/keywords/network_keywords.py +813 -0
  25. pytest_dsl_ui-0.1.0/pytest_dsl_ui/utils/__init__.py +1 -0
  26. pytest_dsl_ui-0.1.0/pytest_dsl_ui/utils/helpers.py +312 -0
  27. pytest_dsl_ui-0.1.0/pytest_dsl_ui/utils/playwright_converter.py +546 -0
  28. pytest_dsl_ui-0.1.0/pytest_dsl_ui.egg-info/PKG-INFO +220 -0
  29. pytest_dsl_ui-0.1.0/pytest_dsl_ui.egg-info/SOURCES.txt +33 -0
  30. pytest_dsl_ui-0.1.0/pytest_dsl_ui.egg-info/dependency_links.txt +1 -0
  31. pytest_dsl_ui-0.1.0/pytest_dsl_ui.egg-info/entry_points.txt +6 -0
  32. pytest_dsl_ui-0.1.0/pytest_dsl_ui.egg-info/requires.txt +11 -0
  33. pytest_dsl_ui-0.1.0/pytest_dsl_ui.egg-info/top_level.txt +1 -0
  34. pytest_dsl_ui-0.1.0/setup.cfg +4 -0
  35. pytest_dsl_ui-0.1.0/tests/test_element_locator.py +288 -0
@@ -0,0 +1,220 @@
1
+ Metadata-Version: 2.4
2
+ Name: pytest-dsl-ui
3
+ Version: 0.1.0
4
+ Summary: Playwright-based UI automation keywords for pytest-dsl framework
5
+ Author: Chen Shuanglin
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/felix-1991/pytest-dsl-ui
8
+ Project-URL: Bug Tracker, https://github.com/felix-1991/pytest-dsl-ui/issues
9
+ Classifier: Framework :: Pytest
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.9
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Operating System :: OS Independent
16
+ Requires-Python: >=3.9
17
+ Description-Content-Type: text/markdown
18
+ Requires-Dist: pytest-dsl>=0.7.0
19
+ Requires-Dist: playwright>=1.40.0
20
+ Requires-Dist: allure-pytest>=2.9.0
21
+ Requires-Dist: Pillow>=9.0.0
22
+ Requires-Dist: ddddocr>=1.4.11
23
+ Provides-Extra: dev
24
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
25
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
26
+ Requires-Dist: black>=22.0.0; extra == "dev"
27
+ Requires-Dist: flake8>=5.0.0; extra == "dev"
28
+
29
+ # pytest-dsl-ui
30
+
31
+ 🎯 **基于Playwright的UI自动化测试框架** - 为pytest-dsl提供强大的Web UI测试能力
32
+
33
+ ## ✨ 核心特性
34
+
35
+ - 🔍 **智能定位器** - 支持20+种元素定位策略,包括复合定位器
36
+ - ⚡ **零配置启动** - 开箱即用,无需复杂配置
37
+ - 🌐 **多浏览器支持** - Chrome、Firefox、Safari、Edge
38
+ - 🔧 **Playwright转换器** - 一键转换录制脚本为DSL格式
39
+
40
+ ## 🚀 快速开始
41
+
42
+ ### 安装
43
+ ```bash
44
+ pip install pytest-dsl-ui
45
+ playwright install # 安装浏览器
46
+ ```
47
+
48
+ ### 5分钟上手示例
49
+ ```dsl
50
+ @name: "百度搜索测试"
51
+
52
+ [启动浏览器], 浏览器: "chromium"
53
+ [打开页面], 地址: "https://www.baidu.com"
54
+ [输入文本], 定位器: "input#kw", 文本: "pytest-dsl-ui"
55
+ [点击元素], 定位器: "input#su"
56
+ [断言文本存在], 文本: "pytest"
57
+ [截图], 文件名: "search_result.png"
58
+ [关闭浏览器]
59
+ ```
60
+
61
+ 运行:`pytest-dsl test.dsl`
62
+
63
+ ## 🎯 定位器速查表
64
+
65
+ > **定位器是框架的核心**,支持简单到复杂的各种定位需求
66
+
67
+ ### 基础定位器
68
+
69
+ | 定位器类型 | 语法格式 | 使用示例 | 说明 |
70
+ |-----------|---------|----------|------|
71
+ | **CSS选择器** | `selector` | `"button.submit"` | 最常用,支持所有CSS选择器 |
72
+ | **文本定位** | `text=文本` | `"text=登录"` | 根据元素文本内容定位 |
73
+ | **角色定位** | `role=角色` | `"role=button"` | 根据ARIA角色定位 |
74
+ | **标签定位** | `label=标签` | `"label=用户名"` | 根据关联的label定位 |
75
+ | **占位符定位** | `placeholder=文本` | `"placeholder=请输入"` | 根据placeholder属性定位 |
76
+ | **测试ID定位** | `testid=ID` | `"testid=submit-btn"` | 根据test-id属性定位 |
77
+ | **XPath定位** | `//xpath` | `"//button[@type='submit']"` | 使用XPath表达式定位 |
78
+
79
+ ### 精确匹配定位器
80
+
81
+ | 定位器类型 | 语法格式 | 使用示例 | 说明 |
82
+ |-----------|---------|----------|------|
83
+ | **精确文本** | `text=文本,exact=true` | `"text=登录,exact=true"` | 精确匹配文本,不包含子串 |
84
+ | **精确标签** | `label=标签,exact=true` | `"label=用户名,exact=true"` | 精确匹配标签文本 |
85
+ | **角色+名称** | `role=角色:名称` | `"role=button:提交"` | 角色和名称的组合定位 |
86
+
87
+ ### 复合定位器 ⭐
88
+
89
+ | 功能 | 语法格式 | 使用示例 | 说明 |
90
+ |------|---------|----------|------|
91
+ | **子元素定位** | `基础定位器&locator=子选择器` | `"role=cell:外到内&locator=label"` | 在基础元素中查找子元素 |
92
+ | **文本过滤** | `基础定位器&has_text=文本` | `"div&has_text=重要"` | 包含特定文本的元素 |
93
+ | **选择第一个** | `基础定位器&first=true` | `"button&first=true"` | 选择第一个匹配的元素 |
94
+ | **选择最后一个** | `基础定位器&last=true` | `"li&last=true"` | 选择最后一个匹配的元素 |
95
+ | **选择第N个** | `基础定位器&nth=索引` | `"option&nth=2"` | 选择第N个元素(从0开始) |
96
+ | **组合条件** | `定位器&条件1&条件2` | `"role=cell:外到内&locator=label&first=true"` | 多个条件组合使用 |
97
+
98
+ ### 智能定位器
99
+
100
+ | 定位器类型 | 语法格式 | 使用示例 | 说明 |
101
+ |-----------|---------|----------|------|
102
+ | **可点击元素** | `clickable=文本` | `"clickable=提交"` | 智能查找可点击的元素 |
103
+ | **元素类型** | `标签名=文本` | `"span=状态"` | 根据HTML标签和文本定位 |
104
+ | **CSS类定位** | `class=类名:文本` | `"class=btn:确认"` | 根据CSS类名和文本定位 |
105
+
106
+ ## 🛠️ 常用操作关键字
107
+
108
+ ### 浏览器控制
109
+ ```dsl
110
+ [启动浏览器], 浏览器: "chromium", 无头模式: false
111
+ [打开页面], 地址: "https://example.com"
112
+ [刷新页面]
113
+ [关闭浏览器]
114
+ ```
115
+
116
+ ### 元素操作
117
+ ```dsl
118
+ [点击元素], 定位器: "button#submit"
119
+ [双击元素], 定位器: "text=编辑"
120
+ [输入文本], 定位器: "input[name='username']", 文本: "admin"
121
+ [清空文本], 定位器: "textarea"
122
+ [选择选项], 定位器: "select", 值: "选项1"
123
+ [上传文件], 定位器: "input[type='file']", 文件路径: "test.jpg"
124
+ ```
125
+
126
+ ### 等待与断言
127
+ ```dsl
128
+ [等待元素出现], 定位器: ".loading"
129
+ [等待元素消失], 定位器: ".spinner"
130
+ [等待文本出现], 文本: "加载完成"
131
+ [断言元素存在], 定位器: ".success"
132
+ [断言文本内容], 定位器: "h1", 预期文本: "欢迎"
133
+ [断言元素可见], 定位器: "button"
134
+ ```
135
+
136
+ ## 🔄 Playwright脚本转换
137
+
138
+ 将Playwright录制的脚本一键转换为DSL格式:
139
+
140
+ ```bash
141
+ # 转换Playwright脚本
142
+ python -m pytest_dsl_ui.utils.playwright_converter input.py -o output.dsl
143
+ ```
144
+
145
+ **转换前(Playwright):**
146
+ ```python
147
+ page.get_by_role("cell", name="外到内").locator("label").first.click()
148
+ page.get_by_text("专家模式", exact=True).click()
149
+ ```
150
+
151
+ **转换后(DSL):**
152
+ ```dsl
153
+ [点击元素], 定位器: "role=cell:外到内&locator=label&first=true"
154
+ [点击元素], 定位器: "text=专家模式,exact=true"
155
+ ```
156
+
157
+ ## 📝 实战示例
158
+
159
+ ### 登录测试
160
+ ```dsl
161
+ @name: "用户登录测试"
162
+
163
+ [启动浏览器], 浏览器: "chromium"
164
+ [打开页面], 地址: "https://example.com/login"
165
+
166
+ # 输入用户名密码
167
+ [输入文本], 定位器: "label=用户名", 文本: "admin"
168
+ [输入文本], 定位器: "placeholder=请输入密码", 文本: "123456"
169
+
170
+ # 点击登录按钮
171
+ [点击元素], 定位器: "role=button:登录"
172
+
173
+ # 验证登录成功
174
+ [等待文本出现], 文本: "欢迎"
175
+ [断言元素存在], 定位器: "text=退出"
176
+ [截图], 文件名: "login_success.png"
177
+
178
+ [关闭浏览器]
179
+ ```
180
+
181
+ ### 表单操作
182
+ ```dsl
183
+ @name: "复杂表单测试"
184
+
185
+ [启动浏览器]
186
+ [打开页面], 地址: "https://example.com/form"
187
+
188
+ # 复合定位器示例
189
+ [点击元素], 定位器: "role=cell:配置项&locator=button&first=true"
190
+ [选择选项], 定位器: "label=类型&locator=select", 值: "高级"
191
+ [输入文本], 定位器: "class=input-group:备注&locator=textarea", 文本: "测试数据"
192
+
193
+ # 提交表单
194
+ [点击元素], 定位器: "clickable=提交"
195
+ [等待文本出现], 文本: "保存成功"
196
+
197
+ [关闭浏览器]
198
+ ```
199
+
200
+ ## 🔧 高级配置
201
+
202
+ ### 设置默认超时
203
+ ```dsl
204
+ [设置等待超时], 超时时间: 30 # 30秒
205
+ ```
206
+
207
+ ### 浏览器选项
208
+ ```dsl
209
+ [启动浏览器], 浏览器: "firefox", 无头模式: true, 视口宽度: 1920, 视口高度: 1080
210
+ ```
211
+
212
+ ## 📚 更多资源
213
+
214
+ - 📖 [完整文档](https://github.com/your-repo/pytest-dsl-ui/docs)
215
+ - 🐛 [问题反馈](https://github.com/your-repo/pytest-dsl-ui/issues)
216
+ - 💡 [示例集合](https://github.com/your-repo/pytest-dsl-ui/examples)
217
+
218
+ ---
219
+
220
+ **💡 提示**:定位器是框架的核心,熟练掌握各种定位器的使用是提高测试效率的关键!
@@ -0,0 +1,192 @@
1
+ # pytest-dsl-ui
2
+
3
+ 🎯 **基于Playwright的UI自动化测试框架** - 为pytest-dsl提供强大的Web UI测试能力
4
+
5
+ ## ✨ 核心特性
6
+
7
+ - 🔍 **智能定位器** - 支持20+种元素定位策略,包括复合定位器
8
+ - ⚡ **零配置启动** - 开箱即用,无需复杂配置
9
+ - 🌐 **多浏览器支持** - Chrome、Firefox、Safari、Edge
10
+ - 🔧 **Playwright转换器** - 一键转换录制脚本为DSL格式
11
+
12
+ ## 🚀 快速开始
13
+
14
+ ### 安装
15
+ ```bash
16
+ pip install pytest-dsl-ui
17
+ playwright install # 安装浏览器
18
+ ```
19
+
20
+ ### 5分钟上手示例
21
+ ```dsl
22
+ @name: "百度搜索测试"
23
+
24
+ [启动浏览器], 浏览器: "chromium"
25
+ [打开页面], 地址: "https://www.baidu.com"
26
+ [输入文本], 定位器: "input#kw", 文本: "pytest-dsl-ui"
27
+ [点击元素], 定位器: "input#su"
28
+ [断言文本存在], 文本: "pytest"
29
+ [截图], 文件名: "search_result.png"
30
+ [关闭浏览器]
31
+ ```
32
+
33
+ 运行:`pytest-dsl test.dsl`
34
+
35
+ ## 🎯 定位器速查表
36
+
37
+ > **定位器是框架的核心**,支持简单到复杂的各种定位需求
38
+
39
+ ### 基础定位器
40
+
41
+ | 定位器类型 | 语法格式 | 使用示例 | 说明 |
42
+ |-----------|---------|----------|------|
43
+ | **CSS选择器** | `selector` | `"button.submit"` | 最常用,支持所有CSS选择器 |
44
+ | **文本定位** | `text=文本` | `"text=登录"` | 根据元素文本内容定位 |
45
+ | **角色定位** | `role=角色` | `"role=button"` | 根据ARIA角色定位 |
46
+ | **标签定位** | `label=标签` | `"label=用户名"` | 根据关联的label定位 |
47
+ | **占位符定位** | `placeholder=文本` | `"placeholder=请输入"` | 根据placeholder属性定位 |
48
+ | **测试ID定位** | `testid=ID` | `"testid=submit-btn"` | 根据test-id属性定位 |
49
+ | **XPath定位** | `//xpath` | `"//button[@type='submit']"` | 使用XPath表达式定位 |
50
+
51
+ ### 精确匹配定位器
52
+
53
+ | 定位器类型 | 语法格式 | 使用示例 | 说明 |
54
+ |-----------|---------|----------|------|
55
+ | **精确文本** | `text=文本,exact=true` | `"text=登录,exact=true"` | 精确匹配文本,不包含子串 |
56
+ | **精确标签** | `label=标签,exact=true` | `"label=用户名,exact=true"` | 精确匹配标签文本 |
57
+ | **角色+名称** | `role=角色:名称` | `"role=button:提交"` | 角色和名称的组合定位 |
58
+
59
+ ### 复合定位器 ⭐
60
+
61
+ | 功能 | 语法格式 | 使用示例 | 说明 |
62
+ |------|---------|----------|------|
63
+ | **子元素定位** | `基础定位器&locator=子选择器` | `"role=cell:外到内&locator=label"` | 在基础元素中查找子元素 |
64
+ | **文本过滤** | `基础定位器&has_text=文本` | `"div&has_text=重要"` | 包含特定文本的元素 |
65
+ | **选择第一个** | `基础定位器&first=true` | `"button&first=true"` | 选择第一个匹配的元素 |
66
+ | **选择最后一个** | `基础定位器&last=true` | `"li&last=true"` | 选择最后一个匹配的元素 |
67
+ | **选择第N个** | `基础定位器&nth=索引` | `"option&nth=2"` | 选择第N个元素(从0开始) |
68
+ | **组合条件** | `定位器&条件1&条件2` | `"role=cell:外到内&locator=label&first=true"` | 多个条件组合使用 |
69
+
70
+ ### 智能定位器
71
+
72
+ | 定位器类型 | 语法格式 | 使用示例 | 说明 |
73
+ |-----------|---------|----------|------|
74
+ | **可点击元素** | `clickable=文本` | `"clickable=提交"` | 智能查找可点击的元素 |
75
+ | **元素类型** | `标签名=文本` | `"span=状态"` | 根据HTML标签和文本定位 |
76
+ | **CSS类定位** | `class=类名:文本` | `"class=btn:确认"` | 根据CSS类名和文本定位 |
77
+
78
+ ## 🛠️ 常用操作关键字
79
+
80
+ ### 浏览器控制
81
+ ```dsl
82
+ [启动浏览器], 浏览器: "chromium", 无头模式: false
83
+ [打开页面], 地址: "https://example.com"
84
+ [刷新页面]
85
+ [关闭浏览器]
86
+ ```
87
+
88
+ ### 元素操作
89
+ ```dsl
90
+ [点击元素], 定位器: "button#submit"
91
+ [双击元素], 定位器: "text=编辑"
92
+ [输入文本], 定位器: "input[name='username']", 文本: "admin"
93
+ [清空文本], 定位器: "textarea"
94
+ [选择选项], 定位器: "select", 值: "选项1"
95
+ [上传文件], 定位器: "input[type='file']", 文件路径: "test.jpg"
96
+ ```
97
+
98
+ ### 等待与断言
99
+ ```dsl
100
+ [等待元素出现], 定位器: ".loading"
101
+ [等待元素消失], 定位器: ".spinner"
102
+ [等待文本出现], 文本: "加载完成"
103
+ [断言元素存在], 定位器: ".success"
104
+ [断言文本内容], 定位器: "h1", 预期文本: "欢迎"
105
+ [断言元素可见], 定位器: "button"
106
+ ```
107
+
108
+ ## 🔄 Playwright脚本转换
109
+
110
+ 将Playwright录制的脚本一键转换为DSL格式:
111
+
112
+ ```bash
113
+ # 转换Playwright脚本
114
+ python -m pytest_dsl_ui.utils.playwright_converter input.py -o output.dsl
115
+ ```
116
+
117
+ **转换前(Playwright):**
118
+ ```python
119
+ page.get_by_role("cell", name="外到内").locator("label").first.click()
120
+ page.get_by_text("专家模式", exact=True).click()
121
+ ```
122
+
123
+ **转换后(DSL):**
124
+ ```dsl
125
+ [点击元素], 定位器: "role=cell:外到内&locator=label&first=true"
126
+ [点击元素], 定位器: "text=专家模式,exact=true"
127
+ ```
128
+
129
+ ## 📝 实战示例
130
+
131
+ ### 登录测试
132
+ ```dsl
133
+ @name: "用户登录测试"
134
+
135
+ [启动浏览器], 浏览器: "chromium"
136
+ [打开页面], 地址: "https://example.com/login"
137
+
138
+ # 输入用户名密码
139
+ [输入文本], 定位器: "label=用户名", 文本: "admin"
140
+ [输入文本], 定位器: "placeholder=请输入密码", 文本: "123456"
141
+
142
+ # 点击登录按钮
143
+ [点击元素], 定位器: "role=button:登录"
144
+
145
+ # 验证登录成功
146
+ [等待文本出现], 文本: "欢迎"
147
+ [断言元素存在], 定位器: "text=退出"
148
+ [截图], 文件名: "login_success.png"
149
+
150
+ [关闭浏览器]
151
+ ```
152
+
153
+ ### 表单操作
154
+ ```dsl
155
+ @name: "复杂表单测试"
156
+
157
+ [启动浏览器]
158
+ [打开页面], 地址: "https://example.com/form"
159
+
160
+ # 复合定位器示例
161
+ [点击元素], 定位器: "role=cell:配置项&locator=button&first=true"
162
+ [选择选项], 定位器: "label=类型&locator=select", 值: "高级"
163
+ [输入文本], 定位器: "class=input-group:备注&locator=textarea", 文本: "测试数据"
164
+
165
+ # 提交表单
166
+ [点击元素], 定位器: "clickable=提交"
167
+ [等待文本出现], 文本: "保存成功"
168
+
169
+ [关闭浏览器]
170
+ ```
171
+
172
+ ## 🔧 高级配置
173
+
174
+ ### 设置默认超时
175
+ ```dsl
176
+ [设置等待超时], 超时时间: 30 # 30秒
177
+ ```
178
+
179
+ ### 浏览器选项
180
+ ```dsl
181
+ [启动浏览器], 浏览器: "firefox", 无头模式: true, 视口宽度: 1920, 视口高度: 1080
182
+ ```
183
+
184
+ ## 📚 更多资源
185
+
186
+ - 📖 [完整文档](https://github.com/your-repo/pytest-dsl-ui/docs)
187
+ - 🐛 [问题反馈](https://github.com/your-repo/pytest-dsl-ui/issues)
188
+ - 💡 [示例集合](https://github.com/your-repo/pytest-dsl-ui/examples)
189
+
190
+ ---
191
+
192
+ **💡 提示**:定位器是框架的核心,熟练掌握各种定位器的使用是提高测试效率的关键!
@@ -0,0 +1,59 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "pytest-dsl-ui"
7
+ version = "0.1.0"
8
+ description = "Playwright-based UI automation keywords for pytest-dsl framework"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = "MIT"
12
+ authors = [
13
+ {name = "Chen Shuanglin"}
14
+ ]
15
+ classifiers = [
16
+ "Framework :: Pytest",
17
+ "Programming Language :: Python :: 3",
18
+ "Programming Language :: Python :: 3.9",
19
+ "Programming Language :: Python :: 3.10",
20
+ "Programming Language :: Python :: 3.11",
21
+ "Programming Language :: Python :: 3.12",
22
+ "Operating System :: OS Independent",
23
+ ]
24
+ dependencies = [
25
+ "pytest-dsl>=0.7.0",
26
+ "playwright>=1.40.0",
27
+ "allure-pytest>=2.9.0",
28
+ "Pillow>=9.0.0", # 用于截图处理
29
+ "ddddocr>=1.4.11", # 用于验证码识别
30
+ ]
31
+
32
+ # 声明entry_points,让pytest-dsl自动发现这个插件
33
+ [project.entry-points."pytest_dsl.keywords"]
34
+ ui_keywords = "pytest_dsl_ui"
35
+
36
+ # 添加控制台脚本入口点
37
+ [project.scripts]
38
+ pw2dsl = "pytest_dsl_ui.utils.playwright_converter:main"
39
+ playwright2dsl = "pytest_dsl_ui.utils.playwright_converter:main"
40
+
41
+ [project.urls]
42
+ "Homepage" = "https://github.com/felix-1991/pytest-dsl-ui"
43
+ "Bug Tracker" = "https://github.com/felix-1991/pytest-dsl-ui/issues"
44
+
45
+ [project.optional-dependencies]
46
+ dev = [
47
+ "pytest>=7.0.0",
48
+ "pytest-cov>=4.0.0",
49
+ "black>=22.0.0",
50
+ "flake8>=5.0.0",
51
+ ]
52
+
53
+ [tool.setuptools]
54
+ packages = {find = {where = ["."], include = ["pytest_dsl_ui*"]}}
55
+
56
+
57
+ [[tool.uv.index]]
58
+ name = "tuna"
59
+ url = "https://mirrors.tuna.tsinghua.edu.cn/pypi/web/simple"
@@ -0,0 +1,39 @@
1
+ """pytest-dsl-ui: Playwright-based UI automation keywords for pytest-dsl
2
+
3
+ 这个包为pytest-dsl框架提供基于Playwright的UI自动化测试关键字。
4
+ 通过entry_points机制自动集成到pytest-dsl中。
5
+ """
6
+
7
+ __version__ = "0.1.0"
8
+ __author__ = "Chen Shuanglin"
9
+
10
+ from pytest_dsl.core.keyword_manager import keyword_manager
11
+
12
+
13
+ def register_keywords(keyword_manager_instance=None):
14
+ """注册所有UI关键字到关键字管理器
15
+
16
+ 这个函数会被pytest-dsl的插件发现机制自动调用。
17
+
18
+ Args:
19
+ keyword_manager_instance: 关键字管理器实例,如果为None则使用全局实例
20
+ """
21
+ if keyword_manager_instance is None:
22
+ keyword_manager_instance = keyword_manager
23
+
24
+ # 导入所有关键字模块,触发关键字注册
25
+ try:
26
+ from . import keywords
27
+ print("pytest-dsl-ui: 已成功加载UI自动化关键字")
28
+ except ImportError as e:
29
+ print(f"pytest-dsl-ui: 加载关键字时出错: {e}")
30
+ raise
31
+
32
+
33
+ # 当模块被直接导入时,自动注册关键字
34
+ # 这确保了即使没有调用register_keywords函数,关键字也会被注册
35
+ try:
36
+ from . import keywords
37
+ except ImportError:
38
+ # 在某些情况下(如安装时),可能无法导入依赖
39
+ pass
@@ -0,0 +1,106 @@
1
+ #!/usr/bin/env python3
2
+ """
3
+ pytest-dsl-ui 包的主入口点
4
+
5
+ 支持通过 python -m pytest_dsl_ui 运行
6
+ """
7
+
8
+ import sys
9
+ import argparse
10
+ from pathlib import Path
11
+
12
+
13
+ def show_help():
14
+ """显示帮助信息"""
15
+ help_text = """
16
+ pytest-dsl-ui 工具集
17
+
18
+ 用法:
19
+ python -m pytest_dsl_ui <command> [options]
20
+
21
+ 命令:
22
+ convert - 转换Playwright脚本为DSL格式
23
+ help - 显示帮助信息
24
+
25
+ 示例:
26
+ # 转换Playwright脚本
27
+ python -m pytest_dsl_ui convert script.py output.dsl
28
+
29
+ # 显示帮助
30
+ python -m pytest_dsl_ui help
31
+ """
32
+ print(help_text.strip())
33
+
34
+
35
+ def convert_command(args):
36
+ """处理转换命令"""
37
+ if len(args) < 1:
38
+ print("错误: convert命令需要输入文件")
39
+ print("用法: python -m pytest_dsl_ui convert <input_file> [output_file]")
40
+ return 1
41
+
42
+ # 导入转换器
43
+ try:
44
+ from .utils.playwright_converter import PlaywrightToDSLConverter
45
+ except ImportError:
46
+ print("错误: 无法导入playwright_converter模块")
47
+ return 1
48
+
49
+ input_file = args[0]
50
+ output_file = args[1] if len(args) > 1 else None
51
+
52
+ # 检查输入文件
53
+ input_path = Path(input_file)
54
+ if not input_path.exists():
55
+ print(f"错误: 输入文件 {input_path} 不存在")
56
+ return 1
57
+
58
+ try:
59
+ # 读取文件
60
+ with open(input_path, 'r', encoding='utf-8') as f:
61
+ script_content = f.read()
62
+
63
+ # 转换
64
+ converter = PlaywrightToDSLConverter()
65
+ dsl_content = converter.convert_script(script_content)
66
+
67
+ # 输出结果
68
+ if output_file:
69
+ output_path = Path(output_file)
70
+ with open(output_path, 'w', encoding='utf-8') as f:
71
+ f.write(dsl_content)
72
+ print(f"转换完成! DSL文件已保存到: {output_path}")
73
+ else:
74
+ print("转换结果:")
75
+ print("=" * 50)
76
+ print(dsl_content)
77
+
78
+ return 0
79
+
80
+ except Exception as e:
81
+ print(f"错误: {e}")
82
+ return 1
83
+
84
+
85
+ def main():
86
+ """主函数"""
87
+ if len(sys.argv) < 2:
88
+ show_help()
89
+ return 0
90
+
91
+ command = sys.argv[1]
92
+ args = sys.argv[2:]
93
+
94
+ if command == 'convert':
95
+ return convert_command(args)
96
+ elif command == 'help':
97
+ show_help()
98
+ return 0
99
+ else:
100
+ print(f"错误: 未知命令 '{command}'")
101
+ show_help()
102
+ return 1
103
+
104
+
105
+ if __name__ == '__main__':
106
+ sys.exit(main())
@@ -0,0 +1 @@
1
+ # Core modules for pytest-dsl-ui