RF_study

RF_study

版权申明:本文为原创文章,转载请注明原文出处

原文链接:http://example.com/post/887fb1e7.html

RF_study

RobotFramework

基于关键字驱动的一种自动化测试框架,能够完美地对WebUI,APPUI,接口实现自动化测试,不需要编写代码,本身基于RF自定义的表格编写语法的形式来实现的工具的自动化测试

不同的测试项,需要不同的库来支撑,WebUI基于Selenium,APPUI基于Appium,接口基于requests

数据驱动:把测试用例数据放到excel/yaml里面,然后通过改变excel、yaml文件里面的数据,达到控制测试用例的执行的过程。

关键字驱动:把项目中的一些业务逻辑或基本的操作封装成一个一个的关键字然后去调用不同的关键字,或者是关键字的组合,去实现一些不同的业务逻辑

特点:

  1. 方便,可以以robot,txt,tsv,html等格式
  2. 可以自动生成html格式的测试报告
  3. 自带很多类库,支持很多扩展库
  4. 可以根据业务需要去自定义关键字(登录、下订单、评论)支持中文
  5. 支持非GUI方法运行,可以和jenkins持续集成
Ride基本使用

项目--模块--子模块--测试套件--测试用例

测试套件(suite)
  • Edit标签:
    • Setting:设置 (Document:描述 Suite Setup:测试套件之前的关键字 Suite Teardown:测试套件之后的关键字 Test Setup:套件用例之前的关键字 Test Teardown:套件用例之后的关键字 Test Template:测试模板 Test Timeout:超时时间 Force Tags:强制标记)
    • 加载外部文件(扩展库,资源文件,变量文件,帮助文档)
    • 定义内部变量
    • 定义元数据
  • Test Edit标签:
  • Run标签:运行
测试用例
  • Edit标签:
    • Setting:设置 (Document:描述 Setup:测试用例之前的关键字 Teardown:测试用例之后的关键字 Template:测试模板 Timeout:超时时间 Tags:标记)
    • 加载外部文件(扩展库,资源文件,变量文件,帮助文档)
    • 定义内部变量
    • 定义元数据
  • Test Edit标签:
  • Run标签:运行
    • Only run tests with these tags(跳过)
    • skip tests with these tags(跳过)
RF类库和扩展库
  1. 标准库(RF自带,不需要额外安装):
    • buitln(测试库)
    • Collection(集合库)
    • DataTime(时间库)
    • screenshot(截屏库)
    • ......
  2. 扩展库(需要通过pip命令额外安装),不同的测试需要不同的库
    • web自动化测试:SeleniumLibrary
    • 接口自动化测试:RequestsLibrary
    • app自动化测试:APPiumLibrary
RF的基本使用
关键字
  • Log:打印

  • ${a} 12:设置变量

    1
    2
    3
    4
    5
    6
    7
    8
    *** Settings ***
    Library DateTime
    *** Keywords ***
    *** Variables ***
    ${a} 0
    *** Test Cases ***
    TEST1
    Log ${a}
  • catenate:字符串拼接

    1
    2
    3
    4
    5
    6
    7
    8
    9
    *** Settings ***
    Library DateTime
    *** Keywords ***
    *** Variables ***

    *** Test Cases ***
    TEST1
    ${str} catenate 1 2 3
    Log ${str}
  • Create List:创建列表

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    *** Settings ***
    Library DateTime
    Library Collections

    *** Keywords ***
    *** Variables ***

    *** Test Cases ***
    TEST1
    ${list} Create List 1 2 3 4 5
    Log ${list}
    @{list} Create List 1 2 3 4 5
    Log Many @{list} #更适合做循环

    输出

    image-20240605161858444

  • 常规关键字

    • 输出:${dict} = {'key1': 'value1', 'key2': 'value2'}

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      *** Settings ***
      Library DateTime
      Library Collections

      *** Keywords ***
      *** Variables ***

      *** Test Cases ***
      TEST1
      ${dict} Create Dictionary key1 value1 key2 value2
      Log ${dict}
    • 获取字典所有的key和value 输出:['key1', 'key2'] ['value1', 'value2']

      1
      2
      3
      4
      5
      6
      7
      8
      TEST1
      ${dict} Create Dictionary key1 value1 key2 value2
      # 获取字典所有的key
      ${keys} Get Dictionary Keys ${dict}
      Log ${keys}
      # 获取字典所有的value
      ${values} Get Dictionary Values ${dict}
      Log ${values}
    • 获取指定key的value

      1
      2
      # 获取指定key的value
      ${value} Get From Dictionary ${dict} key1
  • 复杂关键字

    • 执行python语句 输出:${rand} = 37

      1
      2
      3
      TEST1
      ${rand} Evaluate random.randint(1, 100)
      Log ${rand}
    • 执行py文件里的方法

      image-20240605164228397image-20240605164243888image-20240605164303657

    • if语句

      image-20240605164645024image-20240605164635415

项目规范

项目——init.txt(登陆获取restapi) -> 模块——init.txt(从表格中获取测试需要使用的全局变量,设置测试参数) -> 子模块——init.txt(还原测试环境(每次测试之后都会保存一些变量,重新测试需要删除这些保存的变量)) -> 测试文件(设置默认安全模板,如果是攻击测试,就回放攻击报文,检查是否正常告警)

Author

yyyyyyxnp

Posted on

2024-06-05

Updated on

2024-09-29

Licensed under

You need to set install_url to use ShareThis. Please set it in _config.yml.
You forgot to set the business or currency_code for Paypal. Please set it in _config.yml.

Comments

You forgot to set the shortname for Disqus. Please set it in _config.yml.