This repository has been archived by the owner on Aug 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
334 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,16 @@ | ||
# 工程创建 | ||
# 工程创建 | ||
|
||
创建一个工程目录: | ||
|
||
```bash | ||
mkdir my_autotest | ||
``` | ||
|
||
使用脚手架工具创建用例工程: | ||
|
||
```bash | ||
cd my_autotest/ | ||
youqu3 init | ||
``` | ||
|
||
![](/init.gif) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,137 @@ | ||
# 方法开发 | ||
|
||
## 方法模块路径 | ||
|
||
```shell | ||
my_autotest | ||
├─ case | ||
│ ├─ assert_res | ||
│ │ └─ README.md | ||
│ ├─ base_case.py | ||
│ ├─ test_mycase_001.py | ||
│ └─ test_mycase_002.py | ||
├─ method <--方法模块 # [!code focus] | ||
│ ├─ image_res # [!code focus] | ||
│ │ └─ README.md # [!code focus] | ||
│ ├─ static_res # [!code focus] | ||
│ │ └─ README.md # [!code focus] | ||
│ ├─ assert_method.py # [!code focus] | ||
│ ├─ base_method.py # [!code focus] | ||
│ ├─ my_autotest_method.py # [!code focus] | ||
│ └─ ui.ini # [!code focus] | ||
├─ .gitignore | ||
├─ README.md | ||
├─ config.py | ||
├─ conftest.py | ||
├─ mycase.csv | ||
├─ pytest.ini | ||
├─ requirements.txt | ||
└─ ruff.toml | ||
``` | ||
## 以 dde-dock 方法举例 | ||
::: tip dde_dock_method.py | ||
```python | ||
from funnylog2.config import config as log_config | ||
from youqu3 import log | ||
from youqu3.gui import pylinuxauto | ||
|
||
log_config.CLASS_NAME_ENDSWITH = "Method" | ||
|
||
@log | ||
class DdeDockMethod(): | ||
|
||
@staticmethod | ||
def click_dde_file_manager_on_dock_by_attr(): | ||
"""在任务栏点击文件管理器""" | ||
pylinuxauto.find_element_by_attr_path("/dde-dock/Btn_文件管理器").click() | ||
|
||
@staticmethod | ||
def right_click_dde_file_manager_on_dock_by_attr(): | ||
"""在任务栏右键点击文件管理器""" | ||
pylinuxauto.find_element_by_attr_path("/dde-dock/Btn_文件管理器").right_click() | ||
``` | ||
::: | ||
遵循 PO 设计模式:`一个页面一个类,一个元素一个方法` | ||
## 实践规范 | ||
### 方法文件名称 | ||
- 小驼峰命名。 | ||
- 以`应用名称开头`,如果应用涉及的页面较多需要做划分,可以用页面的名称。 | ||
- 以 `method` 结尾。 | ||
### 类名称 | ||
- 大驼峰命名。 | ||
- 以`应用名称开头`,如果应用涉及的页面较多需要做划分,可以用页面的名称。 | ||
- 以 `Method` 结尾。 | ||
### 方法名称 | ||
```python | ||
def {动词}_{对象}_{位置}_{元素定位方式}(): | ||
... | ||
``` | ||
- 动词开头。 | ||
::: tip 方法动词开头列表 | ||
| 名称 | 单词 | | ||
| :------- | :------------- | | ||
| 左键点击 | `click` | | ||
| 右键点击 | `right_click` | | ||
| 双击 | `double_click` | | ||
| 移动 | `move_to` | | ||
| 拖动 | `drag` | | ||
| 新建 | `new` | | ||
| 拖动到 | `drag_to` | | ||
::: | ||
- 对象,能够直接表示元素对象即可。 | ||
- 位置,对象所在的位置,或者是哪个应用的。 | ||
- 元素定位方式 | ||
::: tip 方法动词开头列表 | ||
| 名称 | 表达式 | | ||
| ------------ | ---------- | | ||
| 属性定位 | `by_attr` | | ||
| 图像识别 | `by_image` | | ||
| OCR识别 | `by_ocr` | | ||
| 相对位置定位 | `by_ui` | | ||
| 键鼠操作 | `by_mk` | | ||
::: | ||
### 函数注释 | ||
```python | ||
def func(): | ||
"""函数注释""" | ||
``` | ||
### 日志 | ||
全自动输出日志,只需要一个类装饰器。 | ||
```python | ||
from funnylog2.config import config as log_config | ||
from youqu3 import log | ||
|
||
log_config.CLASS_NAME_ENDSWITH = "Method" | ||
|
||
@log | ||
class DdeDockMethod(): | ||
... | ||
``` | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,110 @@ | ||
# 用例开发 | ||
# 用例开发 | ||
|
||
## 用例模块路径 | ||
|
||
```shell | ||
my_autotest | ||
├─ case <--用例模块 # [!code focus] | ||
│ ├─ assert_res # [!code focus] | ||
│ │ └─ README.md # [!code focus] | ||
│ ├─ base_case.py # [!code focus] | ||
│ ├─ test_mycase_001.py # [!code focus] | ||
│ └─ test_mycase_002.py v | ||
├─ method | ||
│ ├─ image_res | ||
│ │ └─ README.md | ||
│ ├─ static_res | ||
│ │ └─ README.md | ||
│ ├─ assert_method.py | ||
│ ├─ base_method.py | ||
│ ├─ my_autotest_method.py | ||
│ └─ ui.ini | ||
├─ .gitignore | ||
├─ README.md | ||
├─ config.py | ||
├─ conftest.py | ||
├─ mycase.csv | ||
├─ pytest.ini | ||
├─ requirements.txt | ||
└─ ruff.toml | ||
``` | ||
## 以 dde-file-manager 用例举例 | ||
::: tip case/base_case.py | ||
```python | ||
from method.assert_method import AssertMethod | ||
|
||
|
||
class BaseCase(AssertMethod): | ||
... | ||
``` | ||
::: | ||
::: tip test_dfm_001.py | ||
```python | ||
from youqu3 import sleep | ||
|
||
from case.base_case import BaseCase | ||
from method.dde_dock_method import DdeDockMethod | ||
|
||
|
||
class TestDfm(BaseCase): | ||
|
||
def test_dfm_1159151(self): | ||
"""任务栏右键启动文件管理器""" | ||
# 右键点击任务栏上的文件管理器 | ||
DdeDockMethod.right_click_dde_file_manager_on_dock_by_attr() | ||
# 点击右键菜单中的“打开” | ||
DdeDockMethod.click_open_in_right_menu_by_mk() | ||
sleep(2) | ||
# 断言 | ||
self.assert_process_exist("dde-file-manager") | ||
|
||
def teardown_method(self): | ||
"""teardown""" | ||
DdeDockMethod.kill_process("dde-file-manager") | ||
``` | ||
::: | ||
## 实践规范 | ||
### 用例文件名称 | ||
```bash | ||
test_{case_name}_{case_id}.py | ||
``` | ||
- 小驼峰命名。 | ||
- `test_` 开头。 | ||
- `case_id` 结尾。 | ||
### 类名称 | ||
- 大驼峰命名。 | ||
- 以 `Test` 开头。 | ||
- 以 `用例名称` 结尾,所有用例可以使用相同的类名。 | ||
- 继承 `BaseCase`。 | ||
### 用例函数 | ||
```python | ||
def test_{case_name}_{case_id}(): | ||
... | ||
``` | ||
### 用例注释 | ||
```python | ||
def test_{case_name}_{case_id}(): | ||
"""用例标题""" <--用例注释 # [!code focus] | ||
``` | ||
### CSV文件 | ||
- CSV文件名称对应用例文件名称的 `case_name`:`{case_name}.csv` 。 | ||
- 第一列写 `case_id` 。 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,68 @@ | ||
# 配置模块 | ||
# 配置模块 | ||
|
||
## 配置模块路径 | ||
|
||
```shell | ||
my_autotest | ||
├─ case | ||
│ ├─ assert_res | ||
│ │ └─ README.md | ||
│ ├─ base_case.py | ||
│ ├─ test_mycase_001.py | ||
│ └─ test_mycase_002.py | ||
├─ method | ||
│ ├─ image_res | ||
│ │ └─ README.md | ||
│ ├─ static_res | ||
│ │ └─ README.md | ||
│ ├─ assert_method.py | ||
│ ├─ base_method.py | ||
│ ├─ my_autotest_method.py | ||
│ └─ ui.ini | ||
├─ .gitignore | ||
├─ README.md | ||
├─ config.py <--工程配置 # [!code focus] | ||
├─ conftest.py | ||
├─ mycase.csv | ||
├─ pytest.ini | ||
├─ requirements.txt | ||
└─ ruff.toml | ||
``` | ||
::: tip config.py | ||
```python | ||
import pathlib | ||
|
||
|
||
class _Config: | ||
|
||
ROOTDIR = pathlib.Path(__file__).parent | ||
ASSERT_RES = ROOTDIR / "case/assert_res" | ||
IMAGE_RES = ROOTDIR / "method/image_res" | ||
STATIC_RES = ROOTDIR / "method/static_res" | ||
|
||
|
||
config = _Config() | ||
``` | ||
::: | ||
可以根据需要在里面添加配置。 | ||
## 代码中调用 | ||
```python | ||
from config import config | ||
|
||
config.ROOTDIR | ||
``` | ||
## 调用YouQu3的配置 | ||
```python | ||
from youqu3 import setting | ||
|
||
setting.IS_X11 | ||
``` | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,7 +8,7 @@ | |
mkdir my_autotest | ||
``` | ||
|
||
- 使用脚手架功能创建用例工程 | ||
- 使用脚手架工具创建用例工程 | ||
|
||
```bash | ||
cd my_autotest/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.