RobotFramework笔记

学习目标:

  • 了解 RobotFramework

学习内容:

  1. 搭建 RobotFramework 环境
  2. 掌握 RobotFramework 基本使用
  3. 掌握 RobotFramework 常用类库

【1】RobotFramework 简介和特点

RobotFramework 是一个基于 Python 语言开发的,可扩展的,以关键字驱动模式的自动化测试框架。

关键字驱动:把项目中的一些逻辑封装成关键字(函数名),例如login,register,Set Variable等。调用不同关键字组合实现不同的业务逻辑,从而驱动测试用例执行。

数据驱动:把测试用例的数据提取到excel或者yaml文件中,通过改变excel或者yaml文件中的数据驱动测试用例执行。

Robot Framework 的主要特点包括:

  1. 简单易用: 使用自然语言和关键字来编写测试用例,不需要深入的编程知识。
  2. 平台无关性: 可以在 Windows、Linux、MacOS 等各种平台上运行。
  3. 灵活性: 支持多种测试库和插件,可以轻松扩展和定制。
  4. 可读性: 测试用例具有良好的可读性和可维护性,易于理解和修改。
  5. 丰富的生态系统: 拥有丰富的测试库和工具支持,可以满足各种测试需求。

【2】RobotFramework环境安装(windows)

  1. 安装python3.7并且设置python环境变量
  2. 以管理员身份打开dos窗口
  3. pip install robotframework==3.1
  4. pip install robotframework-ride
  5. 运行ride.py

注:Robot Framework IDE (RIDE)是一个用于编辑和运行RobotFramework测试套件的开发环境(IDE)。

  • 安装过程中可能会报错,需要手动下载wxPython包。
  • 建议使用镜像源下载

RIDE界面


【3】RobotFramework的使用

1. 创建项目

new project

输入项目名称,选择项目路径,选择Dictionary目录
在这里插入图片描述

2. 创建测试套件【测试用例的载体】

new testSuite
选择File
在这里插入图片描述

3.在测试套件下创建测试用例

new testcase
在这里插入图片描述

4. 创建业务关键字(资源文件)【自定义关键字的载体】

new resource
在文件夹下创建,txt格式
在这里插入图片描述

5.在业务关键字下创建用户自定义关键字

new user keyword

在这里插入图片描述


测试套件

Editor页签
      ~~~~~       |- Setting:
           ~~~~~~~~~~            |- Documentation:描述
           ~~~~~~~~~~            |- Suite Setup/Teardown:测试套件的准备/扫尾工作
           ~~~~~~~~~~            |- Test Setup/Teardown :测试用例的准备/扫尾工作
           ~~~~~~~~~~            |- Test Template :测试用例的模板
           ~~~~~~~~~~            |- Test Timeout :测试用例的超时时间
           ~~~~~~~~~~            |- Force Tags :强制标记
           ~~~~~~~~~~            |- Default Tags:默认标记
      ~~~~~       |- Import:
           ~~~~~~~~~~            |- Library:导入外部类库(黑色成功,红色失败)
           ~~~~~~~~~~            |- Source:导入资源文件,如业务关键字
      ~~~~~       |- Variable
      ~~~~~       |- Metadata


测试用例

Editor:在表格内编写测试用例
Text Edit:手动编写
Run:运行用例
在这里插入图片描述
在这里插入图片描述
上图Run页签中常用功能:
Report:报告
Log:日志
Autosave:自动保存
Pause after failure:失败时暂停
Only run tests with these tags:只运行带有这些标记的用例
Skip tests with these tags:跳过带有这些标记的用例


【4】RF常用类库

标准库:RF自带

  1. BuiltIn(测试库)

  2. Collections(集合库)

  3. DateTime(时间库)

  4. ScreenShot(截屏库)

扩展库:需要pip安装

  1. Web自动化测试:SeleniumLibrary,Selenium2Library,Selenium2Library for java等。

  2. API接口自动化:RequestsLibrary

  3. APP自动化测试:AppiumLibrary


【5】RF常用关键字

快捷键:

  • 搜索关键字:F5

  • 自动补全关键字:ctrl+shift+空格

在这里插入图片描述
在这里插入图片描述


【6】UI自动化测试的环境

  • pip install -i https://pypi.tuna.tsinghua.edu.cn/simple robotframework-seleniumlibrary
  • 下载谷歌浏览器
  • 下载谷歌浏览器驱动,chromedriver.exe放到python目录下
  • 在RF的测试套件里面导入SeleniumLibrary

谷歌浏览器驱动地址:
https://getwebdriver.com/chromedriver#stable


【7】浏览器操作的关键字

在这里插入图片描述


【8】元素定位

元素定位的八种方式:

  • id
  • name
  • link_text
  • partial_link_text
  • xpath
  • css
  • class_name
  • tag_name

前提:元素必须唯一

id,name,link,partial link定位:

      ~~~~~       在这里插入图片描述

xpath定位:

  • 通过绝对路径定位(几乎不用)
  • 通过相对路径定位:
          ~~~~~       //form/span/input
  • 通过元素属性定位:
          ~~~~~       //input[@autocomplete=“off”]
          ~~~~~       //input[@autocomplete=“off” and @class=“s_ipt”]
  • 通过部分属性定位:
          ~~~~~      //input[starts-with(@autocomplete,“of”)]或者//input[contains(@autocomplete,“of”)]
  • 通过文本定位:
          ~~~~~      //a[text()=“新闻”]

CSS定位

  • 通过绝对路径定位(几乎不用)

  • 通过ID或者Class定位:
          ~~~~~       #ID
          ~~~~~       .class

  • 通过元素属性定位:
          ~~~~~       一个属性定位 :input[autocomplete=“off”]
          ~~~~~       两个属性同时定位:input[autocomplete=“off”][class=“s_ipt”]

  • 通过部分属性定位:
          ~~~~~       开头:input[autocomplete^=“of”)]
          ~~~~~       结尾:input[autocomplete$=“ff”)]
          ~~~~~       包含:input[autocomplete*=“of”)]

  • 通过子元素定位div#s-top-left a:nth-child(3),id为s-top-left下的第三个a标签。

  • 27
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
回答: 在Robot Framework中,可以使用参数来指定侦听器。参数可以通过冒号或分号作为分隔符来传递给侦听器。如果侦听器是一个绝对路径,冒号后的驱动器不会被视为分隔符。从2.8.7版本开始,也可以使用分号作为参数分隔符。这对于包含冒号的侦听器参数很有用。例如:robot --listener listener.py:arg1:arg2 tests.robot 或 robot --listener "listener.py;arg:with:colons" tests.robot 或 robot --listener C:\Path\Listener.py;D:\data;E:\extra tests.robot。\[1\] 另外,在Robot Framework 2.8.5版本中添加了encoding_errors参数,并在Robot Framework 3.0版本中支持了SYSTEM和CONSOLE编码。可以使用Get File Sizepath来获取文件大小。\[2\] 如果你想获取Robot Framework中的父组件,可以使用python -m robot.libdoc命令来查看父组件的列表。例如:python -m robot.libdoc Selenium2Library显示父组件列表。\[3\] #### 引用[.reference_title] - *1* [robotframework笔记24](https://blog.csdn.net/weixin_30716141/article/details/95784696)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [RobotFramework之OperatingSystem](https://blog.csdn.net/weixin_34381687/article/details/92388378)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] - *3* [Robot Framework用户指南](https://blog.csdn.net/jsd2honey/article/details/78662084)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^control_2,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值