Skip to content
This repository has been archived by the owner on Aug 5, 2024. It is now read-only.

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
mikigo committed Aug 1, 2024
1 parent d579dee commit 6e82608
Show file tree
Hide file tree
Showing 9 changed files with 334 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,9 @@ export default defineConfig({
items: [
{text: "简介", link: "/实践/简介"},
{text: "工程创建", link: "/实践/工程创建"},
{text: "配置模块", link: "/实践/配置模块"},
{text: "方法开发", link: "/实践/方法开发"},
{text: "用例开发", link: "/实践/用例开发"},
{text: "配置模块", link: "/实践/配置模块"},
{text: "依赖管理", link: "/实践/依赖管理"},
]
}
Expand Down
17 changes: 16 additions & 1 deletion docs/实践/工程创建.md
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)
136 changes: 136 additions & 0 deletions docs/实践/方法开发.md
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():
...
```
111 changes: 110 additions & 1 deletion docs/实践/用例开发.md
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`
6 changes: 1 addition & 5 deletions docs/实践/简介.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,7 @@
按照以下章节:

- [工程创建](./工程创建.md):使用 YouQu3 官方提供的脚手架工具,快速创建一个自动化用例工程模板。

- [配置模块](./配置模块.md):介绍自动化用例工程配置模块如何管理配置。

- [方法开发](./方法开发.md):使用 PO 设计理念进行方法封装,方法类如何组织,提高可维护性。

- [用例开发](./用例开发.md):按照业务流程调用方法进行用例代码开发,Fixture 如何编写。

- [配置模块](./配置模块.md):介绍自动化用例工程配置模块如何管理配置。
- [依赖管理](./依赖管理.md):如何管理自动化用例工程的依赖项。
69 changes: 68 additions & 1 deletion docs/实践/配置模块.md
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
```
2 changes: 1 addition & 1 deletion docs/指南/与生俱来/脚手架工具.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
mkdir my_autotest
```

- 使用脚手架功能创建用例工程
- 使用脚手架工具创建用例工程

```bash
cd my_autotest/
Expand Down
3 changes: 1 addition & 2 deletions youqu3/_setting/_setting.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@


class _Setting(_DynamicSetting):
"""Global Config"""
"""YouQu Config"""

PASSWORD: str = os.environ.get("PASSWORD") or "1"

Expand Down Expand Up @@ -49,7 +49,6 @@ class _Setting(_DynamicSetting):
USER_DATE_DIR = "/usr/bin/browser"
HEADLESS = True if os.environ.get("HEADLESS") is None else False

#
PYPI_MIRROR = "https://pypi.tuna.tsinghua.edu.cn/simple"

@dataclasses.dataclass
Expand Down
Loading

0 comments on commit 6e82608

Please sign in to comment.