rtsf


Namertsf JSON
Version 3.0.0 PyPI version JSON
download
home_pagehttps://github.com/RockFeng0/rtsf
Summarya test service framework
upload_time2024-10-31 01:54:57
maintainerNone
docs_urlNone
authorRockFeng0
requires_python!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,<4,>=2.7
licenseMIT
keywords test requests locust http api selenium appium uiautomation
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 项目初衷

> 为什么已经有了[rock4automation](https://github.com/RockFeng0/rock4automation)的自动化测试框架的项目,还要另起一个rtsf项目,并且rtsf中使用的技术,rock4automation项目中已经涵盖?

因为,它存在的痛点很明显:

- rock4automation项目的初衷,是为了能快速重拾技术,是技术的合集,包含了新旧测试的技术。里边一些模块,是冗余的存在,这让项目本身很臃肿。如整合的一些自动化框架,selenium、appium、autoitv3、Microsoft UI Automation等等,关于性能的测试,整合了locust的一些用法。
- rock4automation项目,打包发布的程序,会将源码封装了exe或者加密为pyd,也就是说,发布出来的程序,不是一个源码,而是一个客户端程序,这就有违我开源的意图了
- rock4automation项目,打包了相关工具,比如appium-server,java.exe 等等,大量冗余的非项目源码的工具 

而rtsf(rock4 test service framework)项目的初衷:

- 参考rock4automation和httprunner的项目,我希望能精简一下rtsf,使它**仅仅提供一个测试的关键字驱动和数据驱动的程序框架**。
- 其次,我希望**rtsf是个可扩展的服务框架**,一些自动化技术的框架,可以依托rtsf,迅速形成一个有效的自动化测试相关的业务框架。如整合selenium形成web应用业务的自动化测试框架;整合requests等技术,形成http(s)接口层业务的自动化测试框架等。
- 另外,关于持续继承方面,我希望**rtsf是个命令行的工具**,依托它产生的自动化测试框架,可以接入持续集成的系统。
- 最后,我希望,依托rtsf产生的自动化测试项目,能够轻量,少造轮子,多复用标准库和优秀开源项目,


# 架构

![rtsf架构.png](https://raw.githubusercontent.com/RockFeng0/img-folder/master/rtsf/rtsf架构.png)


## 构建rtsf系列框架

我这里已经完成了几个rtsf+的项目,供大家参考和使用:

- 接口测试[rtsf-http](https://github.com/RockFeng0/rtsf-http)
- 浏览器测试[rtsf-web](https://github.com/RockFeng0/rtsf-web)
- android移动端[rtsf-app](https://github.com/RockFeng0/rtsf-app)
- windows桌面客户端[rtsf-win](https://github.com/RockFeng0/rtsf-win)

其他可接入的方案:
- 计算机视觉opencv
- 图形文字识别tesseract
- 基于像素点对比的图像ImageDiff
- 基于unity3d技术游戏控件识别pocoui

等等

> 测试用例模型,计划扩展为, yaml, xml, excel三种,目前已扩展的只有yaml测试用例模型


# 介绍

## 安装

```
pip install rtsf
```

## rtsf-使用入门

rtsf提供测试执行、报告、日志的基本功能

### 测试用例介绍

- rtsf分三种用例: case、 api、 suite,所以rtsf**支持测试用例分层,允许测试用例的组件化**, 其中api和suite,比case多一个关键字: def
- 测试用例编写过程中,使用api关键字封装当前单个case,允许其他case进行调用,类似调用单个api一样
- 测试用例编写过程中,使用suite关键字,封装当前多个cases,允许其他case进行调用, 类似调用组件化模块一样
- def定义的api和suite,传递参数的替换过程:  当前用例调用api或suite时,**会先将传递的参数值,替换被调用的api或suite中相应的参数**
- api用例的调用过程: 当前用例调用api的时候,如果**当前case与api重复定义键值对时,取当前case中键值对值** 
- suite用例的调用过程: 当前用例调用suite的时候,如果**当前case与suite重复定义键值对,取suite中键值对值**


> 注意: 其内在逻辑,其实是,先加载api和suite,以dict形式存储在内置变量中,然后,加载测试集的用例,如果测试用例使用了api则合并,如果测试用例使用了suite则扩展。

1. case用例: 

```
# test.yaml

- project:
    name: demo project
    module: the module name of testing project

- case:    
    name: case 1

- case:
    name: case call api 1
    api: test1_api()

- case:
    name: case call suite
    api: test_suite(1, 2)

```

2. api用例 

- 在api关键字中中,使用def,表示当前是个 api用例
- api测试用例,可被suite和case重复引入
- 存放路径, case用例同级目录下:  dependencies/api/*。yaml, dependencies/api/*。yml, dependencies/api/*。json
- 沿用case中定义的关键字, 对外调用,使用了def关键字。 其中,def的解析,参照了httprunner项目

```
# test_api.yaml

- api:    
    def: test1_api()

- api:    
    def: test2_api($arg1, $arg2)    
```


3. suite用例

- 在project中,定义def,表示当前整个yaml文件,是一个suite
- suite测试用例, 可被case和其他suite重复引入
- suite测试用例,实际上是,由一些api或者一些case,封装后的,相对稳定的,测试用例
- 存放路径, 测试用例同级目录下:  dependencies/suite/*。yaml, dependencies/suite/*。yml, dependencies/suite/*。json

> suite的用例跟 case差别不大,主要的是,在project中,添加def关键字,定义引入suite的函数入口

```
# test_suite.yaml

- project:
    def: test_suite($arg1, $arg2)

- case:
    name: suite 1

- case:    
    name: suite call api 2
    api: test2_api($arg1, $arg2) 

```

### 测试用例中,函数及变量替换的格式

变量和函数的替换,参照了httprunner项目的格式   该格式取代了我的[rock4automation项目](https://github.com/RockFeng0/rock4automation)中的, #var# 等替换规则

- 引用函数:   ${function_str}
- 引用变量:   $variable_str
- function_str 为字母、数字、下划线、横线、点号、等号、逗号组成的函数. 示例:  /api/${add(1, 2)}?_t=${get_timestamp()}   正则表示为: [a-zA-Z0-9.-_=,]
- function_str若含有特殊字符,将不会被识别, 解决方法是,使用全局变量.   示例,如:  a='@#$%^&'; $print($a)
- variable_str 为字母、数字、下划线组成的变量名.  正则表示为:  [a-zA-Z0-9_]  

### 运行测试用例

使用默认Runner类执行规则,执行test.yaml测试用例

```
from rtsf.p_executer import TestRunner, Runner

runner = TestRunner(runner = Runner).run(r'C:\xxx\xxx\test.yaml')
runner.gen_html_report()
```

- TestRunner(runner = Runner),runner参数用于指定重写了Runner子类,该子类重写了Runner.run_test方法。 默认值为Runner
- TestRunner.run, 该方法,用于**运行指定yaml的case文件**,或者**运行指定文件夹路径中的yaml和json**,如c:\case目录下*.yaml和*.json
- TestRunner。gen_html_report,该方法,用于生成测试报告,报告路径是yaml文件所在路径


### 简单实例

 编写一个测试用例文件,如 example_1.yaml 

```
# example_1.yaml

- project:
    name: demo project
    module: test baidu

- case:    
    name: www.baidu.com

```

example_1执行后的报告:
![实例-1.png](https://raw.githubusercontent.com/RockFeng0/img-folder/master/rtsf/实例-1.png)

**代码,参见项目目录examples/example_1**

### 数据驱动-实例

如下,创建三个文件,example_2.yaml, username_password.csv, devices.csv

```
# example_2.yaml

- project:
    name: demo project
    module: test baidu
    data:
        - csv: devices.csv
          by: Random
        - csv: username_password.csv    

- case:    
    name: www.baidu.com-$username-$password-$devices


# username_password.csv
username,password
15312341230,1234567890
15312341231,1234567891


# devices.csv
devices
android-0
android-1
android-2

```

数据驱动,其实很简单,在yaml的测试用例中,在project块,添加data关键字。

data关键字,以列表形式存在,每个列表项是一个字典,由两个key组成(csv, by)。跟loadrunner中参数化数据一样,csv第一行定义变量,第二行及以下行定义数据驱动的变量值
- csv后面接文件名称,该文件以csv形式存在于case同一路径。
- by是指读取csv格式的顺序, Random or Sequential。默认是Sequential,顺序读取。 该参数,可选填
- 笛卡儿积算法,会对多个data参数进行排列,rtsf会对排列的最终结果遍历执行当前测试集合

example_2执行后的报告,如下, 跑了6条用例,是username_password.csv和devices.csv里边参数的笛卡儿积,username_password默认是顺序,devices是随机。
![实例-2.png](https://raw.githubusercontent.com/RockFeng0/img-folder/master/rtsf/实例-2.png)

**代码,参见项目目录examples/example_2**

### 重写Runner-实例

- rtsf提供入口,允许自定义执行模块的扩展,这个过程有点类似python中重写threading.Thread类.
- 不同的是,rtsf需要重写rtsf.p_executer.Runner.run_test方法

首先, 我们设计我们的yaml用例, 比如,在上面的例子中,加入了几个关键字, responsible, tester, demotest, demoverify

```
# example_3.yaml

- project:
    name: demo project
    module: test baidu

- case:    
    name: demo test
    responsible: your name
    testser: other name
    demotest: ${add(1, 2)}
    demoverify: ${_is(3)}

- case:    
    name: demo test2
    responsible: your name
    testser: other name
    demotest: ${mod(1, 2)}
    demoverify: ${_is(3)} 

- case:    
    name: demo test3
    responsible: your name
    testser: other name
    demotest: ${mod(1, 0)}
    demoverify: ${_is(3)} 

```

然后,重写Runner, 对上面关键字进行功能设置, 重写 Runner.run_test的过程,是使用rtsf的主要工作

- run_test(testcase_dict, variables, driver_map), rtsf在执行测试的时候,调用run_test方法,传入这3个参数

> 注意: 重写的时候,第一个参数,是单个case,不是所有case,**只需要写一个case的执行逻辑**

```
# DemoRunner.py

# encoding:utf-8

from rtsf.p_executer import TestRunner, Runner

def test_add(x, y):
    global result
    result = x+y

def test_mod(x, y):
    global result
    result = x%y

def verify_is(x):
    return result == x    

class DemoRunner(Runner):      

    def __init__(self):
        ''' 继承Runner
        self._default_devices --> list,分布式设备标识。 默认 值 [""],表示本机
        self._default_drivers --》 list, 分布式driver标识与driver键值对。 默认值 [("",None)], 表示本机驱动
        self.parser --> TestCaseParser实例,用于解析用例
        self.tracers --> 每一台分布式设备初始化的Tracer实例,用于记录日志和生成报告       
        self.proj_info --> 记录了用例的项目信息 
        '''
        super(DemoRunner,self).__init__()

    def run_test(self, testcase_dict, variables, driver_map):
        ''' 重写 run_test,有三个参数
        @parm testcase_dict:  单条测试用例
        @param variables: dict; 用例采用数据驱动的情况下,variables是csv文件变量的笛卡儿积;默认情况下值是 {}
        @param driver_map:  tuple;  (唯一标识, driver or module or obj); 默认情况下的值是("",None),该参数适用于selenium的grid有多个 driver的情况
        '''

        # rtsf 遍历 self._default_drivers, 传给 driver_map   这里fn = ''  driver=None
        fn, driver = driver_map

        # 获取 fn 的跟踪对象, 用于记录日志 和 报告
        fn_logger = self.tracers[fn]

        # 获取用例解析对象
        parser = self.parser

        # 绑定测试用例关键字
        yaml_keys = {"add": test_add, "mod": test_mod, '_is': verify_is}
        parser.bind_functions(yaml_keys)        

        # 更新传入的变量
        parser.update_binded_variables(variables)

        # 获取用例名字  
        case_name = testcase_dict.get("name")        

        # parser.eval_content_with_bind_actions 用于解析 字段中的变量和函数,  如:  引用函数: ${function_str} 引用变量: $variable_str
        case_name = parser.eval_content_with_bind_actions(case_name)

        try:
            # fn_logger 可以记录报告,使用:  start, section, step, normal, ok, fail, error, stop
            # start 用于 开始记录报告;  stop 用于结束报告记录
            fn_logger.start(self.proj_info["module"],  # yaml case中 module
                            case_name,  # yaml case中 用例名臣
                            testcase_dict.get("responsible",u"administrator"), # yaml case中responsible定义的责任人名称 
                            testcase_dict.get("tester",u"administrator"), # yaml case中tester定义的测试人名称
                            )

            # fn_logger 可以使用了logging, 记录日志,使用:  log_debug, log_info, log_warning, log_error, log_critical
            fn_logger.log_debug(u"===== run_test\n\t{}".format(testcase_dict))

            fn_logger.section(u"------------starting test")
            # 获取demotest
            demotest = testcase_dict.get("demotest")
            fn_logger.step("got demotest: %s" %demotest)

            parser.eval_content_with_bind_actions(demotest)                
            fn_logger.normal(u"eval demotest. finish")

            # 获取demoverify
            demoverify = testcase_dict.get("demoverify")
            fn_logger.step("got demoverify: %s" %demoverify)

            if parser.eval_content_with_bind_actions(demoverify):
                fn_logger.ok('verify is ok')
            else:
                fn_logger.fail('verify is fail')
            fn_logger.normal(u"eval demoverify. finish")            

        except Exception as e:
            fn_logger.error(e)

        fn_logger.stop()
```
- DemoRunner中,三个内置函数 test_add  test_mod  verify_is 映射到 yaml函数:  add,  mod, _is
- DemoRunner中, 使用Tracer的实例fn_logger,对测试执行过程进行日志和报告的记录,最后使用 fn_logger.stop()结束测试

最后,我们设置runner参数为 DemoRunner, 执行我们自定义的用例逻辑

```
# example_3.py

# encoding:utf-8

from rtsf.p_executer import TestRunner, Runner
from DemoRunner import DemoRunner

runner = TestRunner(runner = DemoRunner).run(r'example_3.yaml')
runner.gen_html_report()
```

example_3执行后的报告,如下,跑了3条用例,1条通过,1条失败,1条报错
![实例-3.png](https://raw.githubusercontent.com/RockFeng0/img-folder/master/rtsf/实例-3.png)

**代码,参见项目目录examples/example_3**

### 测试用例分层(测试组件化)-实例

使用上述的DemoRunner,我们设计下 分层的用例,创建如下三个文件, 文件名可以自定义,路径要正确

- api用例文件,我们使用参数化,使得api用例,可以重复使用
- suite用例文件,我们使用常规的测试手段,封装了正常的测试场景
- 最后,case用例文件,我们做一些异常测试场景

```
# ./dependencies/api/test_api.yaml

- api:    
    def: add_api($arg1, $arg2, $exp)
    demotest: ${add($arg1, $arg2)}
    demoverify: ${_is($exp)}

- api:
    def: mod_api($arg1, $arg2, $exp)
    demotest: ${mod($arg1, $arg2)}
    demoverify: ${_is($exp)} 

# ./dependencies/suite/test_suite.yaml

- project:
    def: suite_test()

- case:
    name: suite 1
    api: add_api(1, 2, 3)

- case:    
    name: suite 2
    api: mod_api(2, 2, 0)

- case:    
    name: suite 3
    demotest: ${add(1, 2)}
    demoverify: ${_is(3)} 

# ./example_4.yaml

- project:
    name: demo project
    module: a demo test

- case:    
    name: case 0
    suite: suite_test()

- case:
    name: case 1
    api: add_api(1, 2, 100)

- case:    
    name: case 2
    api: mod_api(1, 2, 100)

- case:    
    name: case 3
    demotest: ${add(1, 2)}
    demoverify: ${_is(3)} 

```

example_4执行后的报告,如下,跑了6条用例,suite中3条通过,case的3条中,2条失败,1条成功
![实例-4.png](https://raw.githubusercontent.com/RockFeng0/img-folder/master/rtsf/实例-4.png)

**代码,参见项目目录examples/example_4**

### 自定义内置函数
在上述DemoRunner重写 Runner.run_test的过程中,我们定义了三个yaml函数: add, mod, _is, 映射到内置函数, test_add  test_mod  verify_is

rtsf 提供了另一种更简单的方法
1. 定义preference.py,将yaml函数写入 

```
# preference.py

#encoding:utf-8

def add(x, y):
    global result
    result = x+y

def mod(x, y):
    global result
    result = x%y

def _is(x):
    return result == x 
```
2. 注释,DemoRunner中,映射相关代码

```
...

# 绑定测试用例关键字
# yaml_keys = {"add": test_add, "mod": test_mod, 'is': verify_is}
# parser.bind_functions(yaml_keys)
...

```
执行结果,同 example_4

**代码,参见项目目录examples/example_5**

## rtsf-高阶用法

基于约定大于配置的原则,使用rsft构建自己的自动化测试框架

### 约定基本用例结构

,rtsf系列框架,**约定的case基本结构** 如下:

```
- project:    
    name:    
    module:    
    data:
- case:
    name:
    responsible:
    tester:
    glob_var:
    glob_regx:
    pre_command:
    steps:
    post_command:
    verify:
```

> 执行顺序  pre_command(List) -> steps(List) -> post_command(List) -> verify(List)

**preject定义测试集信息**

| project字段               | 描述                                        | 类型              |
| ------------- |:-------------:| -----:|
| name          | 项目名称或待测系统名称(必填)| 字符串       |
| module        | 测试集或功能模块名称(必填) | 字符串       |
| data          | 数据驱动,引用的数据(选填) | 列表      |

**case定义测试用例**

| case字段               | 描述                                        | 类型              |
| ------------- |:-------------:| -----:|
| name          | 描述 用例 (必填),唯一性(必填) | 字符串       |
| responsible   | 用例责任人或者编写人(选填) |字符串           |
| tester        | 用例执行者或者测试人(选填) | 字符串           |
| glob_var      | 全局变量(选填)         | 字典           |
| glob_regx     | 全局正则(选填)         | 字典           |
| pre_command   | 测试的前置步骤或钩子(选填) | 列表           |
| steps         | 测试步骤 (必填)         | 列表           |
| post_command  | 测试的后置步骤或钩子(选填) | 列表           |
| verify        | 校验  (选填)           | 列表           |








            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/RockFeng0/rtsf",
    "name": "rtsf",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,<4,>=2.7",
    "maintainer_email": null,
    "keywords": "test requests locust HTTP api selenium appium uiautomation",
    "author": "RockFeng0",
    "author_email": "281589463@qq.com",
    "download_url": "https://files.pythonhosted.org/packages/78/f4/45ed3832925df3a66c886f8224f7ac9ae7131d16fc287c655ab59db9459e/rtsf-3.0.0.tar.gz",
    "platform": null,
    "description": "# \u9879\u76ee\u521d\u8877\r\n\r\n> \u4e3a\u4ec0\u4e48\u5df2\u7ecf\u6709\u4e86[rock4automation](https://github.com/RockFeng0/rock4automation)\u7684\u81ea\u52a8\u5316\u6d4b\u8bd5\u6846\u67b6\u7684\u9879\u76ee\uff0c\u8fd8\u8981\u53e6\u8d77\u4e00\u4e2artsf\u9879\u76ee\uff0c\u5e76\u4e14rtsf\u4e2d\u4f7f\u7528\u7684\u6280\u672f\uff0crock4automation\u9879\u76ee\u4e2d\u5df2\u7ecf\u6db5\u76d6\uff1f\r\n\r\n\u56e0\u4e3a\uff0c\u5b83\u5b58\u5728\u7684\u75db\u70b9\u5f88\u660e\u663e\uff1a\r\n\r\n- rock4automation\u9879\u76ee\u7684\u521d\u8877\uff0c\u662f\u4e3a\u4e86\u80fd\u5feb\u901f\u91cd\u62fe\u6280\u672f\uff0c\u662f\u6280\u672f\u7684\u5408\u96c6\uff0c\u5305\u542b\u4e86\u65b0\u65e7\u6d4b\u8bd5\u7684\u6280\u672f\u3002\u91cc\u8fb9\u4e00\u4e9b\u6a21\u5757\uff0c\u662f\u5197\u4f59\u7684\u5b58\u5728\uff0c\u8fd9\u8ba9\u9879\u76ee\u672c\u8eab\u5f88\u81c3\u80bf\u3002\u5982\u6574\u5408\u7684\u4e00\u4e9b\u81ea\u52a8\u5316\u6846\u67b6\uff0cselenium\u3001appium\u3001autoitv3\u3001Microsoft UI Automation\u7b49\u7b49\uff0c\u5173\u4e8e\u6027\u80fd\u7684\u6d4b\u8bd5\uff0c\u6574\u5408\u4e86locust\u7684\u4e00\u4e9b\u7528\u6cd5\u3002\r\n- rock4automation\u9879\u76ee,\u6253\u5305\u53d1\u5e03\u7684\u7a0b\u5e8f\uff0c\u4f1a\u5c06\u6e90\u7801\u5c01\u88c5\u4e86exe\u6216\u8005\u52a0\u5bc6\u4e3apyd\uff0c\u4e5f\u5c31\u662f\u8bf4\uff0c\u53d1\u5e03\u51fa\u6765\u7684\u7a0b\u5e8f\uff0c\u4e0d\u662f\u4e00\u4e2a\u6e90\u7801\uff0c\u800c\u662f\u4e00\u4e2a\u5ba2\u6237\u7aef\u7a0b\u5e8f\uff0c\u8fd9\u5c31\u6709\u8fdd\u6211\u5f00\u6e90\u7684\u610f\u56fe\u4e86\r\n- rock4automation\u9879\u76ee,\u6253\u5305\u4e86\u76f8\u5173\u5de5\u5177\uff0c\u6bd4\u5982appium-server\uff0cjava.exe \u7b49\u7b49\uff0c\u5927\u91cf\u5197\u4f59\u7684\u975e\u9879\u76ee\u6e90\u7801\u7684\u5de5\u5177 \r\n\r\n\u800crtsf(rock4 test service framework)\u9879\u76ee\u7684\u521d\u8877\uff1a\r\n\r\n- \u53c2\u8003rock4automation\u548chttprunner\u7684\u9879\u76ee\uff0c\u6211\u5e0c\u671b\u80fd\u7cbe\u7b80\u4e00\u4e0brtsf\uff0c\u4f7f\u5b83**\u4ec5\u4ec5\u63d0\u4f9b\u4e00\u4e2a\u6d4b\u8bd5\u7684\u5173\u952e\u5b57\u9a71\u52a8\u548c\u6570\u636e\u9a71\u52a8\u7684\u7a0b\u5e8f\u6846\u67b6**\u3002\r\n- \u5176\u6b21\uff0c\u6211\u5e0c\u671b**rtsf\u662f\u4e2a\u53ef\u6269\u5c55\u7684\u670d\u52a1\u6846\u67b6**\uff0c\u4e00\u4e9b\u81ea\u52a8\u5316\u6280\u672f\u7684\u6846\u67b6\uff0c\u53ef\u4ee5\u4f9d\u6258rtsf\uff0c\u8fc5\u901f\u5f62\u6210\u4e00\u4e2a\u6709\u6548\u7684\u81ea\u52a8\u5316\u6d4b\u8bd5\u76f8\u5173\u7684\u4e1a\u52a1\u6846\u67b6\u3002\u5982\u6574\u5408selenium\u5f62\u6210web\u5e94\u7528\u4e1a\u52a1\u7684\u81ea\u52a8\u5316\u6d4b\u8bd5\u6846\u67b6\uff1b\u6574\u5408requests\u7b49\u6280\u672f\uff0c\u5f62\u6210http(s)\u63a5\u53e3\u5c42\u4e1a\u52a1\u7684\u81ea\u52a8\u5316\u6d4b\u8bd5\u6846\u67b6\u7b49\u3002\r\n- \u53e6\u5916\uff0c\u5173\u4e8e\u6301\u7eed\u7ee7\u627f\u65b9\u9762\uff0c\u6211\u5e0c\u671b**rtsf\u662f\u4e2a\u547d\u4ee4\u884c\u7684\u5de5\u5177**\uff0c\u4f9d\u6258\u5b83\u4ea7\u751f\u7684\u81ea\u52a8\u5316\u6d4b\u8bd5\u6846\u67b6\uff0c\u53ef\u4ee5\u63a5\u5165\u6301\u7eed\u96c6\u6210\u7684\u7cfb\u7edf\u3002\r\n- \u6700\u540e\uff0c\u6211\u5e0c\u671b\uff0c\u4f9d\u6258rtsf\u4ea7\u751f\u7684\u81ea\u52a8\u5316\u6d4b\u8bd5\u9879\u76ee\uff0c\u80fd\u591f\u8f7b\u91cf\uff0c\u5c11\u9020\u8f6e\u5b50\uff0c\u591a\u590d\u7528\u6807\u51c6\u5e93\u548c\u4f18\u79c0\u5f00\u6e90\u9879\u76ee\uff0c\r\n\r\n\r\n# \u67b6\u6784\r\n\r\n![rtsf\u67b6\u6784.png](https://raw.githubusercontent.com/RockFeng0/img-folder/master/rtsf/rtsf\u67b6\u6784.png)\r\n\r\n\r\n## \u6784\u5efartsf\u7cfb\u5217\u6846\u67b6\r\n\r\n\u6211\u8fd9\u91cc\u5df2\u7ecf\u5b8c\u6210\u4e86\u51e0\u4e2artsf+\u7684\u9879\u76ee,\u4f9b\u5927\u5bb6\u53c2\u8003\u548c\u4f7f\u7528:\r\n\r\n- \u63a5\u53e3\u6d4b\u8bd5[rtsf-http](https://github.com/RockFeng0/rtsf-http)\r\n- \u6d4f\u89c8\u5668\u6d4b\u8bd5[rtsf-web](https://github.com/RockFeng0/rtsf-web)\r\n- android\u79fb\u52a8\u7aef[rtsf-app](https://github.com/RockFeng0/rtsf-app)\r\n- windows\u684c\u9762\u5ba2\u6237\u7aef[rtsf-win](https://github.com/RockFeng0/rtsf-win)\r\n\r\n\u5176\u4ed6\u53ef\u63a5\u5165\u7684\u65b9\u6848:\r\n- \u8ba1\u7b97\u673a\u89c6\u89c9opencv\r\n- \u56fe\u5f62\u6587\u5b57\u8bc6\u522btesseract\r\n- \u57fa\u4e8e\u50cf\u7d20\u70b9\u5bf9\u6bd4\u7684\u56fe\u50cfImageDiff\r\n- \u57fa\u4e8eunity3d\u6280\u672f\u6e38\u620f\u63a7\u4ef6\u8bc6\u522bpocoui\r\n\r\n\u7b49\u7b49\r\n\r\n> \u6d4b\u8bd5\u7528\u4f8b\u6a21\u578b\uff0c\u8ba1\u5212\u6269\u5c55\u4e3a, yaml, xml, excel\u4e09\u79cd\uff0c\u76ee\u524d\u5df2\u6269\u5c55\u7684\u53ea\u6709yaml\u6d4b\u8bd5\u7528\u4f8b\u6a21\u578b\r\n\r\n\r\n# \u4ecb\u7ecd\r\n\r\n## \u5b89\u88c5\r\n\r\n```\r\npip install rtsf\r\n```\r\n\r\n## rtsf-\u4f7f\u7528\u5165\u95e8\r\n\r\nrtsf\u63d0\u4f9b\u6d4b\u8bd5\u6267\u884c\u3001\u62a5\u544a\u3001\u65e5\u5fd7\u7684\u57fa\u672c\u529f\u80fd\r\n\r\n### \u6d4b\u8bd5\u7528\u4f8b\u4ecb\u7ecd\r\n\r\n- rtsf\u5206\u4e09\u79cd\u7528\u4f8b: case\u3001 api\u3001 suite\uff0c\u6240\u4ee5rtsf**\u652f\u6301\u6d4b\u8bd5\u7528\u4f8b\u5206\u5c42\uff0c\u5141\u8bb8\u6d4b\u8bd5\u7528\u4f8b\u7684\u7ec4\u4ef6\u5316**, \u5176\u4e2dapi\u548csuite,\u6bd4case\u591a\u4e00\u4e2a\u5173\u952e\u5b57: def\r\n- \u6d4b\u8bd5\u7528\u4f8b\u7f16\u5199\u8fc7\u7a0b\u4e2d\uff0c\u4f7f\u7528api\u5173\u952e\u5b57\u5c01\u88c5\u5f53\u524d\u5355\u4e2acase\uff0c\u5141\u8bb8\u5176\u4ed6case\u8fdb\u884c\u8c03\u7528,\u7c7b\u4f3c\u8c03\u7528\u5355\u4e2aapi\u4e00\u6837\r\n- \u6d4b\u8bd5\u7528\u4f8b\u7f16\u5199\u8fc7\u7a0b\u4e2d\uff0c\u4f7f\u7528suite\u5173\u952e\u5b57\uff0c\u5c01\u88c5\u5f53\u524d\u591a\u4e2acases\uff0c\u5141\u8bb8\u5176\u4ed6case\u8fdb\u884c\u8c03\u7528\uff0c \u7c7b\u4f3c\u8c03\u7528\u7ec4\u4ef6\u5316\u6a21\u5757\u4e00\u6837\r\n- def\u5b9a\u4e49\u7684api\u548csuite,\u4f20\u9012\u53c2\u6570\u7684\u66ff\u6362\u8fc7\u7a0b:  \u5f53\u524d\u7528\u4f8b\u8c03\u7528api\u6216suite\u65f6\uff0c**\u4f1a\u5148\u5c06\u4f20\u9012\u7684\u53c2\u6570\u503c\uff0c\u66ff\u6362\u88ab\u8c03\u7528\u7684api\u6216suite\u4e2d\u76f8\u5e94\u7684\u53c2\u6570**\r\n- api\u7528\u4f8b\u7684\u8c03\u7528\u8fc7\u7a0b: \u5f53\u524d\u7528\u4f8b\u8c03\u7528api\u7684\u65f6\u5019\uff0c\u5982\u679c**\u5f53\u524dcase\u4e0eapi\u91cd\u590d\u5b9a\u4e49\u952e\u503c\u5bf9\u65f6\uff0c\u53d6\u5f53\u524dcase\u4e2d\u952e\u503c\u5bf9\u503c** \r\n- suite\u7528\u4f8b\u7684\u8c03\u7528\u8fc7\u7a0b: \u5f53\u524d\u7528\u4f8b\u8c03\u7528suite\u7684\u65f6\u5019\uff0c\u5982\u679c**\u5f53\u524dcase\u4e0esuite\u91cd\u590d\u5b9a\u4e49\u952e\u503c\u5bf9\uff0c\u53d6suite\u4e2d\u952e\u503c\u5bf9\u503c**\r\n\r\n\r\n> \u6ce8\u610f: \u5176\u5185\u5728\u903b\u8f91\uff0c\u5176\u5b9e\u662f\uff0c\u5148\u52a0\u8f7dapi\u548csuite,\u4ee5dict\u5f62\u5f0f\u5b58\u50a8\u5728\u5185\u7f6e\u53d8\u91cf\u4e2d\uff0c\u7136\u540e\uff0c\u52a0\u8f7d\u6d4b\u8bd5\u96c6\u7684\u7528\u4f8b\uff0c\u5982\u679c\u6d4b\u8bd5\u7528\u4f8b\u4f7f\u7528\u4e86api\u5219\u5408\u5e76\uff0c\u5982\u679c\u6d4b\u8bd5\u7528\u4f8b\u4f7f\u7528\u4e86suite\u5219\u6269\u5c55\u3002\r\n\r\n1. case\u7528\u4f8b\uff1a \r\n\r\n```\r\n# test.yaml\r\n\r\n- project:\r\n    name: demo project\r\n    module: the module name of testing project\r\n\r\n- case:    \r\n    name: case 1\r\n\r\n- case:\r\n    name: case call api 1\r\n    api: test1_api()\r\n\r\n- case:\r\n    name: case call suite\r\n    api: test_suite(1, 2)\r\n\r\n```\r\n\r\n2. api\u7528\u4f8b \r\n\r\n- \u5728api\u5173\u952e\u5b57\u4e2d\u4e2d\uff0c\u4f7f\u7528def\uff0c\u8868\u793a\u5f53\u524d\u662f\u4e2a api\u7528\u4f8b\r\n- api\u6d4b\u8bd5\u7528\u4f8b\uff0c\u53ef\u88absuite\u548ccase\u91cd\u590d\u5f15\u5165\r\n- \u5b58\u653e\u8def\u5f84, case\u7528\u4f8b\u540c\u7ea7\u76ee\u5f55\u4e0b:  dependencies/api/*\u3002yaml, dependencies/api/*\u3002yml, dependencies/api/*\u3002json\r\n- \u6cbf\u7528case\u4e2d\u5b9a\u4e49\u7684\u5173\u952e\u5b57, \u5bf9\u5916\u8c03\u7528\uff0c\u4f7f\u7528\u4e86def\u5173\u952e\u5b57\u3002 \u5176\u4e2d\uff0cdef\u7684\u89e3\u6790\uff0c\u53c2\u7167\u4e86httprunner\u9879\u76ee\r\n\r\n```\r\n# test_api.yaml\r\n\r\n- api:    \r\n    def: test1_api()\r\n\r\n- api:    \r\n    def: test2_api($arg1, $arg2)    \r\n```\r\n\r\n\r\n3. suite\u7528\u4f8b\r\n\r\n- \u5728project\u4e2d\uff0c\u5b9a\u4e49def\uff0c\u8868\u793a\u5f53\u524d\u6574\u4e2ayaml\u6587\u4ef6\uff0c\u662f\u4e00\u4e2asuite\r\n- suite\u6d4b\u8bd5\u7528\u4f8b\uff0c \u53ef\u88abcase\u548c\u5176\u4ed6suite\u91cd\u590d\u5f15\u5165\r\n- suite\u6d4b\u8bd5\u7528\u4f8b\uff0c\u5b9e\u9645\u4e0a\u662f\uff0c\u7531\u4e00\u4e9bapi\u6216\u8005\u4e00\u4e9bcase\uff0c\u5c01\u88c5\u540e\u7684\uff0c\u76f8\u5bf9\u7a33\u5b9a\u7684\uff0c\u6d4b\u8bd5\u7528\u4f8b\r\n- \u5b58\u653e\u8def\u5f84, \u6d4b\u8bd5\u7528\u4f8b\u540c\u7ea7\u76ee\u5f55\u4e0b:  dependencies/suite/*\u3002yaml, dependencies/suite/*\u3002yml, dependencies/suite/*\u3002json\r\n\r\n> suite\u7684\u7528\u4f8b\u8ddf case\u5dee\u522b\u4e0d\u5927\uff0c\u4e3b\u8981\u7684\u662f\uff0c\u5728project\u4e2d\uff0c\u6dfb\u52a0def\u5173\u952e\u5b57\uff0c\u5b9a\u4e49\u5f15\u5165suite\u7684\u51fd\u6570\u5165\u53e3\r\n\r\n```\r\n# test_suite.yaml\r\n\r\n- project:\r\n    def: test_suite($arg1, $arg2)\r\n\r\n- case:\r\n    name: suite 1\r\n\r\n- case:    \r\n    name: suite call api 2\r\n    api: test2_api($arg1, $arg2) \r\n\r\n```\r\n\r\n### \u6d4b\u8bd5\u7528\u4f8b\u4e2d\uff0c\u51fd\u6570\u53ca\u53d8\u91cf\u66ff\u6362\u7684\u683c\u5f0f\r\n\r\n\u53d8\u91cf\u548c\u51fd\u6570\u7684\u66ff\u6362\uff0c\u53c2\u7167\u4e86httprunner\u9879\u76ee\u7684\u683c\u5f0f   \u8be5\u683c\u5f0f\u53d6\u4ee3\u4e86\u6211\u7684[rock4automation\u9879\u76ee](https://github.com/RockFeng0/rock4automation)\u4e2d\u7684\uff0c #var# \u7b49\u66ff\u6362\u89c4\u5219\r\n\r\n- \u5f15\u7528\u51fd\u6570:   ${function_str}\r\n- \u5f15\u7528\u53d8\u91cf:   $variable_str\r\n- function_str \u4e3a\u5b57\u6bcd\u3001\u6570\u5b57\u3001\u4e0b\u5212\u7ebf\u3001\u6a2a\u7ebf\u3001\u70b9\u53f7\u3001\u7b49\u53f7\u3001\u9017\u53f7\u7ec4\u6210\u7684\u51fd\u6570. \u793a\u4f8b:  /api/${add(1, 2)}?_t=${get_timestamp()}   \u6b63\u5219\u8868\u793a\u4e3a: [a-zA-Z0-9.-_=,]\r\n- function_str\u82e5\u542b\u6709\u7279\u6b8a\u5b57\u7b26\uff0c\u5c06\u4e0d\u4f1a\u88ab\u8bc6\u522b\uff0c \u89e3\u51b3\u65b9\u6cd5\u662f\uff0c\u4f7f\u7528\u5168\u5c40\u53d8\u91cf.   \u793a\u4f8b,\u5982:  a='@#$%^&'; $print($a)\r\n- variable_str \u4e3a\u5b57\u6bcd\u3001\u6570\u5b57\u3001\u4e0b\u5212\u7ebf\u7ec4\u6210\u7684\u53d8\u91cf\u540d.  \u6b63\u5219\u8868\u793a\u4e3a:  [a-zA-Z0-9_]  \r\n\r\n### \u8fd0\u884c\u6d4b\u8bd5\u7528\u4f8b\r\n\r\n\u4f7f\u7528\u9ed8\u8ba4Runner\u7c7b\u6267\u884c\u89c4\u5219\uff0c\u6267\u884ctest.yaml\u6d4b\u8bd5\u7528\u4f8b\r\n\r\n```\r\nfrom rtsf.p_executer import TestRunner, Runner\r\n\r\nrunner = TestRunner(runner = Runner).run(r'C:\\xxx\\xxx\\test.yaml')\r\nrunner.gen_html_report()\r\n```\r\n\r\n- TestRunner(runner = Runner),runner\u53c2\u6570\u7528\u4e8e\u6307\u5b9a\u91cd\u5199\u4e86Runner\u5b50\u7c7b,\u8be5\u5b50\u7c7b\u91cd\u5199\u4e86Runner.run_test\u65b9\u6cd5\u3002 \u9ed8\u8ba4\u503c\u4e3aRunner\r\n- TestRunner.run, \u8be5\u65b9\u6cd5\uff0c\u7528\u4e8e**\u8fd0\u884c\u6307\u5b9ayaml\u7684case\u6587\u4ef6**\uff0c\u6216\u8005**\u8fd0\u884c\u6307\u5b9a\u6587\u4ef6\u5939\u8def\u5f84\u4e2d\u7684yaml\u548cjson**,\u5982c:\\case\u76ee\u5f55\u4e0b*.yaml\u548c*.json\r\n- TestRunner\u3002gen_html_report,\u8be5\u65b9\u6cd5\uff0c\u7528\u4e8e\u751f\u6210\u6d4b\u8bd5\u62a5\u544a\uff0c\u62a5\u544a\u8def\u5f84\u662fyaml\u6587\u4ef6\u6240\u5728\u8def\u5f84\r\n\r\n\r\n### \u7b80\u5355\u5b9e\u4f8b\r\n\r\n \u7f16\u5199\u4e00\u4e2a\u6d4b\u8bd5\u7528\u4f8b\u6587\u4ef6,\u5982 example_1.yaml \r\n\r\n```\r\n# example_1.yaml\r\n\r\n- project:\r\n    name: demo project\r\n    module: test baidu\r\n\r\n- case:    \r\n    name: www.baidu.com\r\n\r\n```\r\n\r\nexample_1\u6267\u884c\u540e\u7684\u62a5\u544a:\r\n![\u5b9e\u4f8b-1.png](https://raw.githubusercontent.com/RockFeng0/img-folder/master/rtsf/\u5b9e\u4f8b-1.png)\r\n\r\n**\u4ee3\u7801\uff0c\u53c2\u89c1\u9879\u76ee\u76ee\u5f55examples/example_1**\r\n\r\n### \u6570\u636e\u9a71\u52a8-\u5b9e\u4f8b\r\n\r\n\u5982\u4e0b\uff0c\u521b\u5efa\u4e09\u4e2a\u6587\u4ef6\uff0cexample_2.yaml, username_password.csv, devices.csv\r\n\r\n```\r\n# example_2.yaml\r\n\r\n- project:\r\n    name: demo project\r\n    module: test baidu\r\n    data:\r\n        - csv: devices.csv\r\n          by: Random\r\n        - csv: username_password.csv    \r\n\r\n- case:    \r\n    name: www.baidu.com-$username-$password-$devices\r\n\r\n\r\n# username_password.csv\r\nusername,password\r\n15312341230,1234567890\r\n15312341231,1234567891\r\n\r\n\r\n# devices.csv\r\ndevices\r\nandroid-0\r\nandroid-1\r\nandroid-2\r\n\r\n```\r\n\r\n\u6570\u636e\u9a71\u52a8\uff0c\u5176\u5b9e\u5f88\u7b80\u5355\uff0c\u5728yaml\u7684\u6d4b\u8bd5\u7528\u4f8b\u4e2d\uff0c\u5728project\u5757\uff0c\u6dfb\u52a0data\u5173\u952e\u5b57\u3002\r\n\r\ndata\u5173\u952e\u5b57\uff0c\u4ee5\u5217\u8868\u5f62\u5f0f\u5b58\u5728\uff0c\u6bcf\u4e2a\u5217\u8868\u9879\u662f\u4e00\u4e2a\u5b57\u5178\uff0c\u7531\u4e24\u4e2akey\u7ec4\u6210(csv, by)\u3002\u8ddfloadrunner\u4e2d\u53c2\u6570\u5316\u6570\u636e\u4e00\u6837\uff0ccsv\u7b2c\u4e00\u884c\u5b9a\u4e49\u53d8\u91cf\uff0c\u7b2c\u4e8c\u884c\u53ca\u4ee5\u4e0b\u884c\u5b9a\u4e49\u6570\u636e\u9a71\u52a8\u7684\u53d8\u91cf\u503c\r\n- csv\u540e\u9762\u63a5\u6587\u4ef6\u540d\u79f0\uff0c\u8be5\u6587\u4ef6\u4ee5csv\u5f62\u5f0f\u5b58\u5728\u4e8ecase\u540c\u4e00\u8def\u5f84\u3002\r\n- by\u662f\u6307\u8bfb\u53d6csv\u683c\u5f0f\u7684\u987a\u5e8f\uff0c Random or Sequential\u3002\u9ed8\u8ba4\u662fSequential\uff0c\u987a\u5e8f\u8bfb\u53d6\u3002 \u8be5\u53c2\u6570\uff0c\u53ef\u9009\u586b\r\n- \u7b1b\u5361\u513f\u79ef\u7b97\u6cd5\uff0c\u4f1a\u5bf9\u591a\u4e2adata\u53c2\u6570\u8fdb\u884c\u6392\u5217\uff0crtsf\u4f1a\u5bf9\u6392\u5217\u7684\u6700\u7ec8\u7ed3\u679c\u904d\u5386\u6267\u884c\u5f53\u524d\u6d4b\u8bd5\u96c6\u5408\r\n\r\nexample_2\u6267\u884c\u540e\u7684\u62a5\u544a\uff0c\u5982\u4e0b\uff0c \u8dd1\u4e866\u6761\u7528\u4f8b\uff0c\u662fusername_password.csv\u548cdevices.csv\u91cc\u8fb9\u53c2\u6570\u7684\u7b1b\u5361\u513f\u79ef\uff0cusername_password\u9ed8\u8ba4\u662f\u987a\u5e8f\uff0cdevices\u662f\u968f\u673a\u3002\r\n![\u5b9e\u4f8b-2.png](https://raw.githubusercontent.com/RockFeng0/img-folder/master/rtsf/\u5b9e\u4f8b-2.png)\r\n\r\n**\u4ee3\u7801\uff0c\u53c2\u89c1\u9879\u76ee\u76ee\u5f55examples/example_2**\r\n\r\n### \u91cd\u5199Runner-\u5b9e\u4f8b\r\n\r\n- rtsf\u63d0\u4f9b\u5165\u53e3\uff0c\u5141\u8bb8\u81ea\u5b9a\u4e49\u6267\u884c\u6a21\u5757\u7684\u6269\u5c55\uff0c\u8fd9\u4e2a\u8fc7\u7a0b\u6709\u70b9\u7c7b\u4f3cpython\u4e2d\u91cd\u5199threading.Thread\u7c7b.\r\n- \u4e0d\u540c\u7684\u662f\uff0crtsf\u9700\u8981\u91cd\u5199rtsf.p_executer.Runner.run_test\u65b9\u6cd5\r\n\r\n\u9996\u5148\uff0c \u6211\u4eec\u8bbe\u8ba1\u6211\u4eec\u7684yaml\u7528\u4f8b\uff0c \u6bd4\u5982\uff0c\u5728\u4e0a\u9762\u7684\u4f8b\u5b50\u4e2d\uff0c\u52a0\u5165\u4e86\u51e0\u4e2a\u5173\u952e\u5b57\uff0c responsible, tester, demotest, demoverify\r\n\r\n```\r\n# example_3.yaml\r\n\r\n- project:\r\n    name: demo project\r\n    module: test baidu\r\n\r\n- case:    \r\n    name: demo test\r\n    responsible: your name\r\n    testser: other name\r\n    demotest: ${add(1, 2)}\r\n    demoverify: ${_is(3)}\r\n\r\n- case:    \r\n    name: demo test2\r\n    responsible: your name\r\n    testser: other name\r\n    demotest: ${mod(1, 2)}\r\n    demoverify: ${_is(3)} \r\n\r\n- case:    \r\n    name: demo test3\r\n    responsible: your name\r\n    testser: other name\r\n    demotest: ${mod(1, 0)}\r\n    demoverify: ${_is(3)} \r\n\r\n```\r\n\r\n\u7136\u540e\uff0c\u91cd\u5199Runner\uff0c \u5bf9\u4e0a\u9762\u5173\u952e\u5b57\u8fdb\u884c\u529f\u80fd\u8bbe\u7f6e\uff0c \u91cd\u5199 Runner.run_test\u7684\u8fc7\u7a0b\uff0c\u662f\u4f7f\u7528rtsf\u7684\u4e3b\u8981\u5de5\u4f5c\r\n\r\n- run_test(testcase_dict, variables, driver_map), rtsf\u5728\u6267\u884c\u6d4b\u8bd5\u7684\u65f6\u5019\uff0c\u8c03\u7528run_test\u65b9\u6cd5\uff0c\u4f20\u5165\u8fd93\u4e2a\u53c2\u6570\r\n\r\n> \u6ce8\u610f: \u91cd\u5199\u7684\u65f6\u5019\uff0c\u7b2c\u4e00\u4e2a\u53c2\u6570\uff0c\u662f\u5355\u4e2acase\uff0c\u4e0d\u662f\u6240\u6709case\uff0c**\u53ea\u9700\u8981\u5199\u4e00\u4e2acase\u7684\u6267\u884c\u903b\u8f91**\r\n\r\n```\r\n# DemoRunner.py\r\n\r\n# encoding:utf-8\r\n\r\nfrom rtsf.p_executer import TestRunner, Runner\r\n\r\ndef test_add(x, y):\r\n    global result\r\n    result = x+y\r\n\r\ndef test_mod(x, y):\r\n    global result\r\n    result = x%y\r\n\r\ndef verify_is(x):\r\n    return result == x    \r\n\r\nclass DemoRunner(Runner):      \r\n\r\n    def __init__(self):\r\n        ''' \u7ee7\u627fRunner\r\n        self._default_devices --> list,\u5206\u5e03\u5f0f\u8bbe\u5907\u6807\u8bc6\u3002 \u9ed8\u8ba4 \u503c [\"\"]\uff0c\u8868\u793a\u672c\u673a\r\n        self._default_drivers --\u300b list, \u5206\u5e03\u5f0fdriver\u6807\u8bc6\u4e0edriver\u952e\u503c\u5bf9\u3002 \u9ed8\u8ba4\u503c [(\"\",None)]\uff0c \u8868\u793a\u672c\u673a\u9a71\u52a8\r\n        self.parser --> TestCaseParser\u5b9e\u4f8b\uff0c\u7528\u4e8e\u89e3\u6790\u7528\u4f8b\r\n        self.tracers --> \u6bcf\u4e00\u53f0\u5206\u5e03\u5f0f\u8bbe\u5907\u521d\u59cb\u5316\u7684Tracer\u5b9e\u4f8b\uff0c\u7528\u4e8e\u8bb0\u5f55\u65e5\u5fd7\u548c\u751f\u6210\u62a5\u544a       \r\n        self.proj_info --> \u8bb0\u5f55\u4e86\u7528\u4f8b\u7684\u9879\u76ee\u4fe1\u606f \r\n        '''\r\n        super(DemoRunner,self).__init__()\r\n\r\n    def run_test(self, testcase_dict, variables, driver_map):\r\n        ''' \u91cd\u5199 run_test\uff0c\u6709\u4e09\u4e2a\u53c2\u6570\r\n        @parm testcase_dict:  \u5355\u6761\u6d4b\u8bd5\u7528\u4f8b\r\n        @param variables: dict; \u7528\u4f8b\u91c7\u7528\u6570\u636e\u9a71\u52a8\u7684\u60c5\u51b5\u4e0b\uff0cvariables\u662fcsv\u6587\u4ef6\u53d8\u91cf\u7684\u7b1b\u5361\u513f\u79ef\uff1b\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u503c\u662f {}\r\n        @param driver_map:  tuple;  (\u552f\u4e00\u6807\u8bc6, driver or module or obj); \u9ed8\u8ba4\u60c5\u51b5\u4e0b\u7684\u503c\u662f(\"\",None),\u8be5\u53c2\u6570\u9002\u7528\u4e8eselenium\u7684grid\u6709\u591a\u4e2a driver\u7684\u60c5\u51b5\r\n        '''\r\n\r\n        # rtsf \u904d\u5386 self._default_drivers, \u4f20\u7ed9 driver_map   \u8fd9\u91ccfn = ''  driver=None\r\n        fn, driver = driver_map\r\n\r\n        # \u83b7\u53d6 fn \u7684\u8ddf\u8e2a\u5bf9\u8c61\uff0c \u7528\u4e8e\u8bb0\u5f55\u65e5\u5fd7 \u548c \u62a5\u544a\r\n        fn_logger = self.tracers[fn]\r\n\r\n        # \u83b7\u53d6\u7528\u4f8b\u89e3\u6790\u5bf9\u8c61\r\n        parser = self.parser\r\n\r\n        # \u7ed1\u5b9a\u6d4b\u8bd5\u7528\u4f8b\u5173\u952e\u5b57\r\n        yaml_keys = {\"add\": test_add, \"mod\": test_mod, '_is': verify_is}\r\n        parser.bind_functions(yaml_keys)        \r\n\r\n        # \u66f4\u65b0\u4f20\u5165\u7684\u53d8\u91cf\r\n        parser.update_binded_variables(variables)\r\n\r\n        # \u83b7\u53d6\u7528\u4f8b\u540d\u5b57  \r\n        case_name = testcase_dict.get(\"name\")        \r\n\r\n        # parser.eval_content_with_bind_actions \u7528\u4e8e\u89e3\u6790 \u5b57\u6bb5\u4e2d\u7684\u53d8\u91cf\u548c\u51fd\u6570\uff0c  \u5982:  \u5f15\u7528\u51fd\u6570: ${function_str} \u5f15\u7528\u53d8\u91cf: $variable_str\r\n        case_name = parser.eval_content_with_bind_actions(case_name)\r\n\r\n        try:\r\n            # fn_logger \u53ef\u4ee5\u8bb0\u5f55\u62a5\u544a\uff0c\u4f7f\u7528:  start, section, step, normal, ok, fail, error, stop\r\n            # start \u7528\u4e8e \u5f00\u59cb\u8bb0\u5f55\u62a5\u544a\uff1b  stop \u7528\u4e8e\u7ed3\u675f\u62a5\u544a\u8bb0\u5f55\r\n            fn_logger.start(self.proj_info[\"module\"],  # yaml case\u4e2d module\r\n                            case_name,  # yaml case\u4e2d \u7528\u4f8b\u540d\u81e3\r\n                            testcase_dict.get(\"responsible\",u\"administrator\"), # yaml case\u4e2dresponsible\u5b9a\u4e49\u7684\u8d23\u4efb\u4eba\u540d\u79f0 \r\n                            testcase_dict.get(\"tester\",u\"administrator\"), # yaml case\u4e2dtester\u5b9a\u4e49\u7684\u6d4b\u8bd5\u4eba\u540d\u79f0\r\n                            )\r\n\r\n            # fn_logger \u53ef\u4ee5\u4f7f\u7528\u4e86logging, \u8bb0\u5f55\u65e5\u5fd7\uff0c\u4f7f\u7528:  log_debug, log_info, log_warning, log_error, log_critical\r\n            fn_logger.log_debug(u\"===== run_test\\n\\t{}\".format(testcase_dict))\r\n\r\n            fn_logger.section(u\"------------starting test\")\r\n            # \u83b7\u53d6demotest\r\n            demotest = testcase_dict.get(\"demotest\")\r\n            fn_logger.step(\"got demotest: %s\" %demotest)\r\n\r\n            parser.eval_content_with_bind_actions(demotest)                \r\n            fn_logger.normal(u\"eval demotest. finish\")\r\n\r\n            # \u83b7\u53d6demoverify\r\n            demoverify = testcase_dict.get(\"demoverify\")\r\n            fn_logger.step(\"got demoverify: %s\" %demoverify)\r\n\r\n            if parser.eval_content_with_bind_actions(demoverify):\r\n                fn_logger.ok('verify is ok')\r\n            else:\r\n                fn_logger.fail('verify is fail')\r\n            fn_logger.normal(u\"eval demoverify. finish\")            \r\n\r\n        except Exception as e:\r\n            fn_logger.error(e)\r\n\r\n        fn_logger.stop()\r\n```\r\n- DemoRunner\u4e2d\uff0c\u4e09\u4e2a\u5185\u7f6e\u51fd\u6570 test_add  test_mod  verify_is \u6620\u5c04\u5230 yaml\u51fd\u6570:  add,  mod, _is\r\n- DemoRunner\u4e2d\uff0c \u4f7f\u7528Tracer\u7684\u5b9e\u4f8bfn_logger\uff0c\u5bf9\u6d4b\u8bd5\u6267\u884c\u8fc7\u7a0b\u8fdb\u884c\u65e5\u5fd7\u548c\u62a5\u544a\u7684\u8bb0\u5f55\uff0c\u6700\u540e\u4f7f\u7528 fn_logger.stop()\u7ed3\u675f\u6d4b\u8bd5\r\n\r\n\u6700\u540e\uff0c\u6211\u4eec\u8bbe\u7f6erunner\u53c2\u6570\u4e3a DemoRunner, \u6267\u884c\u6211\u4eec\u81ea\u5b9a\u4e49\u7684\u7528\u4f8b\u903b\u8f91\r\n\r\n```\r\n# example_3.py\r\n\r\n# encoding:utf-8\r\n\r\nfrom rtsf.p_executer import TestRunner, Runner\r\nfrom DemoRunner import DemoRunner\r\n\r\nrunner = TestRunner(runner = DemoRunner).run(r'example_3.yaml')\r\nrunner.gen_html_report()\r\n```\r\n\r\nexample_3\u6267\u884c\u540e\u7684\u62a5\u544a\uff0c\u5982\u4e0b\uff0c\u8dd1\u4e863\u6761\u7528\u4f8b\uff0c1\u6761\u901a\u8fc7\uff0c1\u6761\u5931\u8d25\uff0c1\u6761\u62a5\u9519\r\n![\u5b9e\u4f8b-3.png](https://raw.githubusercontent.com/RockFeng0/img-folder/master/rtsf/\u5b9e\u4f8b-3.png)\r\n\r\n**\u4ee3\u7801\uff0c\u53c2\u89c1\u9879\u76ee\u76ee\u5f55examples/example_3**\r\n\r\n### \u6d4b\u8bd5\u7528\u4f8b\u5206\u5c42(\u6d4b\u8bd5\u7ec4\u4ef6\u5316)-\u5b9e\u4f8b\r\n\r\n\u4f7f\u7528\u4e0a\u8ff0\u7684DemoRunner\uff0c\u6211\u4eec\u8bbe\u8ba1\u4e0b \u5206\u5c42\u7684\u7528\u4f8b\uff0c\u521b\u5efa\u5982\u4e0b\u4e09\u4e2a\u6587\u4ef6, \u6587\u4ef6\u540d\u53ef\u4ee5\u81ea\u5b9a\u4e49\uff0c\u8def\u5f84\u8981\u6b63\u786e\r\n\r\n- api\u7528\u4f8b\u6587\u4ef6\uff0c\u6211\u4eec\u4f7f\u7528\u53c2\u6570\u5316\uff0c\u4f7f\u5f97api\u7528\u4f8b\uff0c\u53ef\u4ee5\u91cd\u590d\u4f7f\u7528\r\n- suite\u7528\u4f8b\u6587\u4ef6\uff0c\u6211\u4eec\u4f7f\u7528\u5e38\u89c4\u7684\u6d4b\u8bd5\u624b\u6bb5\uff0c\u5c01\u88c5\u4e86\u6b63\u5e38\u7684\u6d4b\u8bd5\u573a\u666f\r\n- \u6700\u540e\uff0ccase\u7528\u4f8b\u6587\u4ef6\uff0c\u6211\u4eec\u505a\u4e00\u4e9b\u5f02\u5e38\u6d4b\u8bd5\u573a\u666f\r\n\r\n```\r\n# ./dependencies/api/test_api.yaml\r\n\r\n- api:    \r\n    def: add_api($arg1, $arg2, $exp)\r\n    demotest: ${add($arg1, $arg2)}\r\n    demoverify: ${_is($exp)}\r\n\r\n- api:\r\n    def: mod_api($arg1, $arg2, $exp)\r\n    demotest: ${mod($arg1, $arg2)}\r\n    demoverify: ${_is($exp)} \r\n\r\n# ./dependencies/suite/test_suite.yaml\r\n\r\n- project:\r\n    def: suite_test()\r\n\r\n- case:\r\n    name: suite 1\r\n    api: add_api(1, 2, 3)\r\n\r\n- case:    \r\n    name: suite 2\r\n    api: mod_api(2, 2, 0)\r\n\r\n- case:    \r\n    name: suite 3\r\n    demotest: ${add(1, 2)}\r\n    demoverify: ${_is(3)} \r\n\r\n# ./example_4.yaml\r\n\r\n- project:\r\n    name: demo project\r\n    module: a demo test\r\n\r\n- case:    \r\n    name: case 0\r\n    suite: suite_test()\r\n\r\n- case:\r\n    name: case 1\r\n    api: add_api(1, 2, 100)\r\n\r\n- case:    \r\n    name: case 2\r\n    api: mod_api(1, 2, 100)\r\n\r\n- case:    \r\n    name: case 3\r\n    demotest: ${add(1, 2)}\r\n    demoverify: ${_is(3)} \r\n\r\n```\r\n\r\nexample_4\u6267\u884c\u540e\u7684\u62a5\u544a\uff0c\u5982\u4e0b\uff0c\u8dd1\u4e866\u6761\u7528\u4f8b\uff0csuite\u4e2d3\u6761\u901a\u8fc7\uff0ccase\u76843\u6761\u4e2d\uff0c2\u6761\u5931\u8d25\uff0c1\u6761\u6210\u529f\r\n![\u5b9e\u4f8b-4.png](https://raw.githubusercontent.com/RockFeng0/img-folder/master/rtsf/\u5b9e\u4f8b-4.png)\r\n\r\n**\u4ee3\u7801\uff0c\u53c2\u89c1\u9879\u76ee\u76ee\u5f55examples/example_4**\r\n\r\n### \u81ea\u5b9a\u4e49\u5185\u7f6e\u51fd\u6570\r\n\u5728\u4e0a\u8ff0DemoRunner\u91cd\u5199 Runner.run_test\u7684\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e09\u4e2ayaml\u51fd\u6570: add, mod, _is, \u6620\u5c04\u5230\u5185\u7f6e\u51fd\u6570\uff0c test_add  test_mod  verify_is\r\n\r\nrtsf \u63d0\u4f9b\u4e86\u53e6\u4e00\u79cd\u66f4\u7b80\u5355\u7684\u65b9\u6cd5\r\n1. \u5b9a\u4e49preference.py\uff0c\u5c06yaml\u51fd\u6570\u5199\u5165 \r\n\r\n```\r\n# preference.py\r\n\r\n#encoding:utf-8\r\n\r\ndef add(x, y):\r\n    global result\r\n    result = x+y\r\n\r\ndef mod(x, y):\r\n    global result\r\n    result = x%y\r\n\r\ndef _is(x):\r\n    return result == x \r\n```\r\n2. \u6ce8\u91ca\uff0cDemoRunner\u4e2d\uff0c\u6620\u5c04\u76f8\u5173\u4ee3\u7801\r\n\r\n```\r\n...\r\n\r\n# \u7ed1\u5b9a\u6d4b\u8bd5\u7528\u4f8b\u5173\u952e\u5b57\r\n# yaml_keys = {\"add\": test_add, \"mod\": test_mod, 'is': verify_is}\r\n# parser.bind_functions(yaml_keys)\r\n...\r\n\r\n```\r\n\u6267\u884c\u7ed3\u679c\uff0c\u540c example_4\r\n\r\n**\u4ee3\u7801\uff0c\u53c2\u89c1\u9879\u76ee\u76ee\u5f55examples/example_5**\r\n\r\n## rtsf-\u9ad8\u9636\u7528\u6cd5\r\n\r\n\u57fa\u4e8e\u7ea6\u5b9a\u5927\u4e8e\u914d\u7f6e\u7684\u539f\u5219\uff0c\u4f7f\u7528rsft\u6784\u5efa\u81ea\u5df1\u7684\u81ea\u52a8\u5316\u6d4b\u8bd5\u6846\u67b6\r\n\r\n### \u7ea6\u5b9a\u57fa\u672c\u7528\u4f8b\u7ed3\u6784\r\n\r\n\uff0crtsf\u7cfb\u5217\u6846\u67b6\uff0c**\u7ea6\u5b9a\u7684case\u57fa\u672c\u7ed3\u6784** \u5982\u4e0b\uff1a\r\n\r\n```\r\n- project:    \r\n    name:    \r\n    module:    \r\n    data:\r\n- case:\r\n    name:\r\n    responsible:\r\n    tester:\r\n    glob_var:\r\n    glob_regx:\r\n    pre_command:\r\n    steps:\r\n    post_command:\r\n    verify:\r\n```\r\n\r\n> \u6267\u884c\u987a\u5e8f  pre_command(List) -> steps(List) -> post_command(List) -> verify(List)\r\n\r\n**preject\u5b9a\u4e49\u6d4b\u8bd5\u96c6\u4fe1\u606f**\r\n\r\n| project\u5b57\u6bb5               | \u63cf\u8ff0                                        | \u7c7b\u578b              |\r\n| ------------- |:-------------:| -----:|\r\n| name          | \u9879\u76ee\u540d\u79f0\u6216\u5f85\u6d4b\u7cfb\u7edf\u540d\u79f0(\u5fc5\u586b)| \u5b57\u7b26\u4e32       |\r\n| module        | \u6d4b\u8bd5\u96c6\u6216\u529f\u80fd\u6a21\u5757\u540d\u79f0(\u5fc5\u586b) | \u5b57\u7b26\u4e32       |\r\n| data          | \u6570\u636e\u9a71\u52a8\uff0c\u5f15\u7528\u7684\u6570\u636e(\u9009\u586b) | \u5217\u8868      |\r\n\r\n**case\u5b9a\u4e49\u6d4b\u8bd5\u7528\u4f8b**\r\n\r\n| case\u5b57\u6bb5               | \u63cf\u8ff0                                        | \u7c7b\u578b              |\r\n| ------------- |:-------------:| -----:|\r\n| name          | \u63cf\u8ff0 \u7528\u4f8b (\u5fc5\u586b)\uff0c\u552f\u4e00\u6027(\u5fc5\u586b) | \u5b57\u7b26\u4e32       |\r\n| responsible   | \u7528\u4f8b\u8d23\u4efb\u4eba\u6216\u8005\u7f16\u5199\u4eba(\u9009\u586b) |\u5b57\u7b26\u4e32           |\r\n| tester        | \u7528\u4f8b\u6267\u884c\u8005\u6216\u8005\u6d4b\u8bd5\u4eba(\u9009\u586b) | \u5b57\u7b26\u4e32           |\r\n| glob_var      | \u5168\u5c40\u53d8\u91cf(\u9009\u586b)         | \u5b57\u5178           |\r\n| glob_regx     | \u5168\u5c40\u6b63\u5219(\u9009\u586b)         | \u5b57\u5178           |\r\n| pre_command   | \u6d4b\u8bd5\u7684\u524d\u7f6e\u6b65\u9aa4\u6216\u94a9\u5b50(\u9009\u586b) | \u5217\u8868           |\r\n| steps         | \u6d4b\u8bd5\u6b65\u9aa4 (\u5fc5\u586b)         | \u5217\u8868           |\r\n| post_command  | \u6d4b\u8bd5\u7684\u540e\u7f6e\u6b65\u9aa4\u6216\u94a9\u5b50(\u9009\u586b) | \u5217\u8868           |\r\n| verify        | \u6821\u9a8c  (\u9009\u586b)           | \u5217\u8868           |\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "a test service framework",
    "version": "3.0.0",
    "project_urls": {
        "Homepage": "https://github.com/RockFeng0/rtsf"
    },
    "split_keywords": [
        "test",
        "requests",
        "locust",
        "http",
        "api",
        "selenium",
        "appium",
        "uiautomation"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "a8bc89ace6662008f73632d6d18192a730b0725628e2b5da6062f5b9e1c5bdc6",
                "md5": "15efc336e2be11eb65eeca10d8ae6364",
                "sha256": "fd825cea0e488d7d6f2cc51b6bd1bc3b7cd724db9e191039b19e399e44ec0056"
            },
            "downloads": -1,
            "filename": "rtsf-3.0.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "15efc336e2be11eb65eeca10d8ae6364",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,<4,>=2.7",
            "size": 35865,
            "upload_time": "2024-10-31T01:54:55",
            "upload_time_iso_8601": "2024-10-31T01:54:55.840867Z",
            "url": "https://files.pythonhosted.org/packages/a8/bc/89ace6662008f73632d6d18192a730b0725628e2b5da6062f5b9e1c5bdc6/rtsf-3.0.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "78f445ed3832925df3a66c886f8224f7ac9ae7131d16fc287c655ab59db9459e",
                "md5": "0e1b69f99c611984712608f2e7a1b88b",
                "sha256": "4b8e7858d3cc1299eac4ce63c21db1dc46570a027f41bc61847258e2da2274ca"
            },
            "downloads": -1,
            "filename": "rtsf-3.0.0.tar.gz",
            "has_sig": false,
            "md5_digest": "0e1b69f99c611984712608f2e7a1b88b",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "!=3.0.*,!=3.1.*,!=3.2.*,!=3.3.*,<4,>=2.7",
            "size": 41347,
            "upload_time": "2024-10-31T01:54:57",
            "upload_time_iso_8601": "2024-10-31T01:54:57.877753Z",
            "url": "https://files.pythonhosted.org/packages/78/f4/45ed3832925df3a66c886f8224f7ac9ae7131d16fc287c655ab59db9459e/rtsf-3.0.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-31 01:54:57",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "RockFeng0",
    "github_project": "rtsf",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "lcname": "rtsf"
}
        
Elapsed time: 0.32397s