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

Commit

Permalink
fix: update
Browse files Browse the repository at this point in the history
Description:

Log:
  • Loading branch information
mikigo committed Jun 28, 2024
1 parent aa8c298 commit cd84cc1
Show file tree
Hide file tree
Showing 13 changed files with 513 additions and 42 deletions.
10 changes: 5 additions & 5 deletions docs/.vitepress/config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ export default defineConfig({
// https://vitepress.dev/reference/default-theme-config
siteTitle: "YouQu3",
nav: [
{text: '首页', link: '/index'},
{text: '指南', link: '/指南/简介/YouQu3是什么'},
{text: '插件', link: '/插件/插件列表'},
{text: '设计', link: '/设计/YouQu3架构设计规划'},
{text: '🏠 首页', link: '/index'},
{text: '🧭 指南', link: '/指南/简介/YouQu3是什么'},
{text: '🔌 插件', link: '/插件/插件列表'},
{text: '🎵 设计', link: '/设计/YouQu3架构设计规划'},
],

sidebar: {
Expand Down Expand Up @@ -66,7 +66,7 @@ export default defineConfig({
{text: "断言语句", link: "/指南/与生俱来/断言语句"},
{text: "文件操控", link: "/指南/与生俱来/文件操控"},
{text: "动态等待", link: "/指南/与生俱来/动态等待"},
{text: "JSON报告", link: "/指南/与生俱来/文件操控"},
{text: "JSON报告", link: "/指南/与生俱来/JSON报告"},
{text: "前后钩子", link: "/指南/与生俱来/前后钩子"},
]
},
Expand Down
Binary file added docs/assets/指南/与生俱来/assert.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ features:
details: 继承YouQu2诸多亮点功能的同时解决其遇到的问题,各方面全面优化,更多玩法姿势等你来解锁。
- icon: 🛀
title: 新体验
details: 更加简单易用、更加纯粹、扩展性和兼容性更好,一秒入魂
details: 更加简单易用、更加纯粹、扩展性和兼容性更好,一发入魂

---

Expand Down
105 changes: 105 additions & 0 deletions docs/指南/与生俱来/JSON报告.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
# JSON 报告

框架默认生成 JSON 报告,在用例工程目录下生成报告文件: `/report/json/report_xxxx.json`

## 报告内容

### 整体结构

```json
{
"created": 1518371686.7981803,
"duration": 0.1235666275024414,
"exitcode": 1,
"root": "/path/to/tests",
"environment": ENVIRONMENT,
"summary": SUMMARY,
"collectors": COLLECTORS,
"tests": TESTS,
"warnings": WARNINGS,
}
```

### Environment

环境信息

```json
{
"Python": "3.6.4",
"Platform": "Linux-4.56.78-9-ARCH-x86_64-with-arch",
"Packages": {
"pytest": "3.4.0",
"py": "1.5.2",
"pluggy": "0.6.0"
},
"Plugins": {
"xdist": "1.22.0",
"metadata": "1.5.1",
},
"foo": "bar"
}
```

### Summary

汇总信息

```json
{
"collected": 10,
"passed": 2,
"failed": 3,
"xfailed": 1,
"xpassed": 1,
"error": 2,
"skipped": 1,
"total": 10
}
```

### Collectors

收集器节点的列表,默认关闭,不显示。

### Tests

每个用例的详细结果

```json
[
{
"nodeid": "test_foo.py::test_fail",
"lineno": 50,
"keywords": [
"test_fail",
"test_foo.py",
"test_foo0"
],
"outcome": "failed",
"setup": TEST_STAGE,
"call": TEST_STAGE,
"teardown": TEST_STAGE,
"metadata": {
"foo": "bar",
}
},
...
]
```

### Warnings

警告信息

```json
[
{
"code": "C1",
"path": "/path/to/tests/test_foo.py",
"nodeid": "test_foo.py::TestFoo",
"message": "cannot collect test class 'TestFoo' because it has a __init__ constructor"
}
]
```

61 changes: 61 additions & 0 deletions docs/指南/与生俱来/前后钩子.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
# 前后钩子

YouQu3 提供灵活的前后钩子机制。

## 前置钩子

### 前置脚本钩子

在用例工程目录下存放一个 `job_start.py` 的脚本,框架会在用例执行之前自动加载并执行。

```bash
my_case
├── case
├── method
├── job_start.py # [!code focus]
...
```
### 前置命令行入参钩子
框架支持通过 `--job-start` 入参,参数值可以传递任意命令行命令,框架会在用例执行之前执行。
```bash
youqu3 run --job-start "python3 do_what_you_want_do.py"
```
就像写 Shell 脚本一样即可:
```bash
youqu3 run --job-start "sudo apt install htop;git clone ..."
```
## 后置钩子
### 后置脚本钩子
在用例工程目录下存放一个 `job_start.py` 的脚本,框架会在用例执行之前自动加载并执行。
```bash
my_case
├── case
├── method
├── job_end.py # [!code focus]
...
```
### 后置命令行入参钩子
框架支持通过 `--job-end` 入参,参数值可以传递任意命令行命令,框架会在用例执行之前执行。
```bash
youqu3 run --job-end "python3 do_what_you_want_do.py"
```
就像写 Shell 脚本一样即可:
```bash
youqu3 run --job-end "sudo apt install htop;git clone ..."
```
##
31 changes: 31 additions & 0 deletions docs/指南/与生俱来/动态等待.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# 动态等待

## 架构动态等待

```python
from youqu3 import sleep

sleep(1)
```

可以完全代替之前这样的写法:

```python
from time import sleep
```

优化:

- 增加了等待的日志

- 根据不同的架构对等待时间进行倍数放大,各架构倍数:

```ini
x86_64 = 1
aarch64 = 1.5
loongarch64 = 2
mips64 = 2.5
sw_64 = 2.5
```

## 元素识别动态等待
58 changes: 58 additions & 0 deletions docs/指南/与生俱来/命令行交互.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# 命令行交互

## 本机命令行交互

### 普通权限执行

```python
from youqu3.cmd import Cmd

Cmd.run("ls")
```

### sudo权限执行

```python
from youqu3.cmd import Cmd

Cmd.sudo_run("apt install htop")
```

### expect交互

```python
from youqu3.cmd import Cmd

Cmd.expect_run(
"ssh username@machine_ip 'ls -l'",
events={'password':'secret\n'}
)
```

## 远程命令行交互

### 普通权限执行

```python
from youqu3.cmd import RemoteCmd

RemoteCmd("user", "ip", "password").remote_run("ls -l")
```

### sudo权限执行

```python
from youqu3.cmd import RemoteCmd

RemoteCmd("user", "ip", "password").remote_sudo_run("apt install htop")
```

### expect交互

```python
from youqu3.cmd import RemoteCmd

# TODO
# RemoteCmd("user", "ip", "password").remote_expect_run("sudo apt install htop")
```

50 changes: 50 additions & 0 deletions docs/指南/与生俱来/断言语句.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# 断言语句

YouQu3 自带多种断言语句,几乎满足了所有的断言场景;

![](/指南/与生俱来/assert.png)

## 用例中使用方法

APP 工程自有断言模块:`assert_method.py`,它继承了 YouQu3 框架的断言库:

```python
# assert_method.py

from youqu3.assertx import Assert

class AssertMethod(Assert):
"""AssertMethod"""

```

用例基类 `BaseCase` 继承 `AssertMethod`

```python
# base_case.py

from method.assert_method import AssertMethod
from youqu3.webui import WebAssert

class BaseCase(AssertMethod, WebAssert):
"""用例基类"""
```

用例中通过 `self` 调用所有的断言语句:

```python
class TestMyCase(BaseCase):

def test_mycase_001(self):
"""my case 001"""
self.assert_xxx
```

## 方法明细

```python
<!--@include: ../../../youqu3/assertx.py-->
```



Loading

0 comments on commit cd84cc1

Please sign in to comment.