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 Jul 22, 2024
1 parent 036be33 commit 944f4fa
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 44 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
</p>
<h1 align="center">YouQu3</h1>
<p align="center">
<em>YouQu3, Next generation Linux automation testing framework.</em>
<em>YouQu3, Next-Gen Linux Autotest Framework.</em>
</p>


Expand Down Expand Up @@ -41,7 +41,7 @@
pip install youqu3
```

![](docs/assets/instalk.gif)
![](docs/assets/install.gif)

## 创建用例工程

Expand Down
18 changes: 18 additions & 0 deletions docs/指南/与生俱来/脚手架工具.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# 脚手架工具

使用子命令 `init` 创建用例工程,工程遵循完整的 PO 设计模式,让你可以专注于用例和方法的编写维护。

- 创建一个目录

```bash
mkdir my_autotest
```

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

```bash
cd my_autotest/
youqu3 init
```

![](/init.gif)
37 changes: 32 additions & 5 deletions docs/指南/驱动执行/自定义执行.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,48 @@

YouQu3 支持在 txt 文件中自定义用例集驱动执行:

- youqu-tags.txt
- youqu-keywords.txt
- `youqu-tags.txt`
- `youqu-keywords.txt`

## youqu-tags.txt

在根目录下定义 `youqu-tags.txt` 文件,YouQu3 会自动加载并执行。

`youqu-tags.txt` 文件里面写标签的表达式,如:
`youqu-tags.txt` 文件里面写`标签`的表达式,如:

::: tip youqu-tags.txt
```txt
id1 or id2 or id3
```

## youqu-keywords.txt

在根目录下定义 `youqu-keywords.txt` 文件,YouQu3 会自动加载并执行。

`youqu-keywords.txt` 文件里面写`关键词`的表达式,如:

```txt
id1 or id2 or id3
```

## 案例

### PMS用例驱动

[youqu-pms-driver](https://github.com/funny-dream/youqu-pms-driver):从PMS测试单中爬取用例集,将用例 id 集合写入 `youqu-tags.txt` 文件。

使用框架的[前置钩子](https://youqu.uniontech.com/v3/%E6%8C%87%E5%8D%97/%E4%B8%8E%E7%94%9F%E4%BF%B1%E6%9D%A5/%E5%89%8D%E5%90%8E%E9%92%A9%E5%AD%90.html#%E5%89%8D%E7%BD%AE%E9%92%A9%E5%AD%90)触发爬取动作生成 `youqu-tags.txt` 文件,框架自动加载并执行对应标签的用例。

使用框架的[后置钩子](https://youqu.uniontech.com/v3/%E6%8C%87%E5%8D%97/%E4%B8%8E%E7%94%9F%E4%BF%B1%E6%9D%A5/%E5%89%8D%E5%90%8E%E9%92%A9%E5%AD%90.html#%E5%90%8E%E7%BD%AE%E9%92%A9%E5%AD%90)触发结果回填到 PMS 测试单。

执行命令:
::: code-group
```bash [原生环境]
youqu3 run --job-start "pms-driver --task-id 123456 --pms-user ut001234 --pms-password xxxx" --job-end "pms-driver --task-id 123456 --pms-user ut001234 --pms-password xxxx --send2pms"
```
```bash [虚拟环境]
youqu3-cargo run --job-start "pms-driver --task-id 123456 --pms-user ut001234 --pms-password xxxx" --job-end "pms-driver --task-id 123456 --pms-user ut001234 --pms-password xxxx --send2pms"
```
:::



## youqu-keywords.txt
4 changes: 2 additions & 2 deletions docs/指南/驱动执行/远程执行.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@

::: code-group
```bash [原生环境]
$ youqu3 remote -e
$ youqu3 remote
```
```bash [虚拟环境]
$ youqu3-cargo remote -e
$ youqu3-cargo remote
```
:::

Expand Down
14 changes: 4 additions & 10 deletions youqu3/assertx.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,6 @@ def assert_image_exist(
)
except exceptions.TemplateElementNotFound as exc:
raise AssertionError(exc) from exceptions.TemplateElementNotFound
except Exception as exc:
raise exceptions.AssertOptionError(exc) from Exception

@classmethod
def assert_image_exist_during_time(
Expand All @@ -72,8 +70,6 @@ def assert_image_exist_during_time(
pylinuxauto.get_during(widget, screen_time, rate, pause)
except exceptions.TemplateElementNotFound as exc:
raise AssertionError(exc) from exceptions.TemplateElementNotFound
except Exception as exc:
raise exceptions.AssertOptionError(exc) from Exception

@staticmethod
def assert_image_not_exist(
Expand Down Expand Up @@ -111,8 +107,6 @@ def assert_image_not_exist(
pass
except exceptions.TemplateElementFound as exc:
raise AssertionError(exc) from exceptions.TemplateElementFound
except Exception as exc:
raise exceptions.AssertOptionError(exc) from Exception

@staticmethod
def assert_file_exist(file_path):
Expand All @@ -122,7 +116,7 @@ def assert_file_exist(file_path):
"""
logger.info(f"断言文件存在 <{file_path}>")
if not os.path.exists(os.path.expanduser(file_path)):
raise AssertionError(f"文件不存在! 路径 {file_path}")
raise AssertionError(f"文件不存在:{file_path}")
return True

@staticmethod
Expand All @@ -135,7 +129,7 @@ def assert_file_not_exist(file_path):
"""
logger.info(f"断言文件不存在 <{file_path}>")
if os.path.exists(os.path.expanduser(file_path)):
raise AssertionError(f"文件存在! 路径 {file_path}")
raise AssertionError(f"文件存在:{file_path}")

@staticmethod
def assert_element_exist(expr):
Expand All @@ -146,7 +140,7 @@ def assert_element_exist(expr):
logger.info(f"断言元素存在<{expr}>")
from youqu3.gui import pylinuxauto
if not pylinuxauto.find_element_by_attr_path(expr):
raise AssertionError(f"元素不存在!!!expr= <{expr}>")
raise AssertionError(f"元素不存在:{expr}")

@staticmethod
def assert_element_not_exist(expr):
Expand All @@ -158,7 +152,7 @@ def assert_element_not_exist(expr):
from youqu3.gui import pylinuxauto
try:
pylinuxauto.find_element_by_attr_path(expr)
raise AssertionError(f"元素不应存在!!!expr= <{expr}>")
raise AssertionError(f"元素不应该存在:{expr}")
except exceptions.ElementNotFound:
pass

Expand Down
26 changes: 1 addition & 25 deletions youqu3/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
class ApplicationStartError(Exception):

def __init__(self, result):
"""
应用程序未启动
:param result: 结果
"""
err = f"应用程序未启动: {result}"
logger.error(err)
Exception.__init__(self, err)
Expand All @@ -21,10 +17,6 @@ def __init__(self, result):
class ElementNotFound(Exception):

def __init__(self, name):
"""
未找到元素
:param name: 命令
"""
err = f"未找到元素: {name}"
logger.error(err)
Exception.__init__(self, err)
Expand All @@ -33,10 +25,6 @@ def __init__(self, name):
class TemplateElementNotFound(Exception):

def __init__(self, *name):
"""
通过模板资源未匹配到对应元素
:param name: 命令
"""
err = "未在屏幕上匹配到图片: "
template = [f"{i}.png" for i in name]
logger.error(f"{err}{str(*template)}")
Expand All @@ -46,10 +34,6 @@ def __init__(self, *name):
class TemplateElementFound(Exception):

def __init__(self, *name):
"""
通过模板资源匹配到对应元素
:param name: 命令
"""
err = "在屏幕中匹配到了不应该出现的元素: "
template = [f"{i}.png" for i in name]
logger.error(f"{err}{str(*template)}")
Expand All @@ -59,10 +43,6 @@ def __init__(self, *name):
class TemplatePictureNotExist(Exception):

def __init__(self, name):
"""
文件不存在
:param name: 命令
"""
err = f"图片文件不存在: {name} "
logger.error(err)
Exception.__init__(self, err)
Expand All @@ -71,10 +51,6 @@ def __init__(self, name):
class ParamError(Exception):

def __init__(self, name, msg):
"""
参数错误
:param name: 命令
"""
err = f"参数错误:{name}\n{msg}"
logger.error(err)
Exception.__init__(self, err)
Expand All @@ -91,6 +67,6 @@ def __init__(self, msg):
class YouQuPluginDependencyError(Exception):

def __init__(self, msg):
err = f"YouQu插件未安装 {msg}, 请尝试安装: pip install {msg}"
err = f"YouQu3插件未安装 {msg}, 请尝试安装: pip install {msg}"
logger.error(err)
Exception.__init__(self, err)

0 comments on commit 944f4fa

Please sign in to comment.