当前位置: 首页 > news >正文

RobotFramework测试框架(1)--官网示例

 示例 项目

RF官网提供了几个例子

Examples Overview | ROBOT FRAMEWORK

Vehicle Insurance App

根据下面的例子可以看到,RF的测试文件,包含

*** Settings ***-用来引入库和资源

*** Variables *** 用来指定变量,在测试用例中可使用${}来引用。

*** Test Cases *** 下面为用例,其中用例Create Quote for Car下包含的关键字,都是在*** Keywords ***中自定义的。

[Documentation] 用来定义测试用例的文档

[Tags] 用来定义测试用例的tag

*** Keywords *** 定义关键字,关键字下调用Browser库文件中的关键字

  1. [Arguments] firstname=Max{lastname}=Mustermann

    • 这行定义了这个关键字需要的参数及其默认值。在这个例子中,Enter Insurant Data 关键字接受两个参数:firstname 和 lastname。如果调用这个关键字时没有提供这些参数的值,那么它们将分别默认为 Max 和 Mustermann
*** Settings ***
Library    Browser*** Variables ***
${BROWSER}    chromium
${HEADLESS}    false*** Test Cases ***
Create Quote for CarOpen Insurance ApplicationEnter Vehicle Data for AutomobileEnter Insurant DataEnter Product DataSelect Price OptionSend QuoteEnd Test*** Keywords ***
Open Insurance ApplicationNew Browser    browser=${BROWSER}    headless=${HEADLESS}New Context    locale=en-GBNew Page    http://sampleapp.tricentis.com/Enter Vehicle Data for AutomobileClick    div.main-navigation >> "Automobile"Select Options By    id=make    text    AudiFill Text    id=engineperformance    110Fill Text    id=dateofmanufacture    06/12/1980Select Options By    id=numberofseats    text    5Select Options By    id=fuel    text    Petrol    Fill Text    id=listprice    30000Fill Text    id=licenseplatenumber    DMK1234Fill Text    id=annualmileage   10000 Click    section[style="display: block;"] >> text=Next »Enter Insurant Data[Arguments]    ${firstname}=Max    ${lastname}=MustermannFill Text    id=firstname    MaxFill Text    id=lastname    MustermannFill Text    id=birthdate    01/31/1980Check Checkbox    *css=label >> id=gendermaleFill Text    id=streetaddress    Test StreetSelect Options By    id=country    text    GermanyFill Text    id=zipcode    40123Fill Text    id=city    EssenSelect Options By    id=occupation    text    EmployeeClick    text=Cliff DivingClick    section[style="display: block;"] >> text=Next »Enter Product DataFill Text    id=startdate    06/01/2023Select Options By    id=insurancesum    text    7.000.000,00Select Options By    id=meritrating    text    Bonus 1Select Options By    id=damageinsurance    text    No CoverageCheck Checkbox    *css=label >> id=EuroProtectionSelect Options By    id=courtesycar    text    YesClick    section[style="display: block;"] >> text=Next »Select Price Option[Arguments]    ${price_option}=SilverClick    *css=label >> css=[value=${price_option}]Click    section[style="display: block;"] >> text=Next »Send QuoteFill Text    "E-Mail" >> .. >> input    max.mustermann@example.comFill Text    "Phone" >> .. >> input    0049201123456Fill Text    "Username" >> .. >> input    max.mustermannFill Text    "Password" >> .. >> input    SecretPassword123!Fill Text    "Confirm Password" >> .. >> input    SecretPassword123!Fill Text    "Comments" >> .. >> textarea    Some comments${promise}=     Promise To    Wait For Response     matcher=http://sampleapp.tricentis.com/101/tcpdf/pdfs/quote.php     timeout=10Click    "« Send »"${body}=    Wait For    ${promise}Log    ${body}[status]Log    ${body}[body]Wait For Elements State    "Sending e-mail success!"Click    "OK"End TestClose ContextClose Browser

WFA login

这个例子中引用了py文件中的函数

另外在Settings里可以使用Suite Setup和Suite Teardown进行test suite级别的测试数据准备和清理

Test Setup和Suite Teardown进行test级别前置和后置准备。

*** Settings ***
Library    Browser
Library    totp.py
Suite Setup    New Browser    browser=${BROWSER}    headless=${HEADLESS}
Test Setup    New Context
Test Teardown    Close Context
Suite Teardown    Close Browser*** Variables ***
${BROWSER}    chromium
${HEADLESS}    False*** Test Cases ***
Login with MFANew Page    https://seleniumbase.io/realworld/loginFill Text    id=username    demo_userFill Text    id=password    secret_pass${totp}    Get Totp    GAXG2MTEOR3DMMDGFill Text    id=totpcode     ${totp}Click    "Sign in"Get Text  h1  ==  Welcome!

import pyotpdef get_totp(secret):totp = pyotp.TOTP(secret)return totp.now()

Restful Booker

*** Settings ***
Library    RequestsLibrary
Library    Collections
Suite Setup    Authenticate as Admin*** Test Cases ***
Get Bookings from Restful Booker${body}    Create Dictionary    firstname=John${response}    GET    https://restful-booker.herokuapp.com/booking    ${body}Status Should Be    200Log List    ${response.json()}FOR  ${booking}  IN  @{response.json()}${response}    GET    https://restful-booker.herokuapp.com/booking/${booking}[bookingid]TRYLog    ${response.json()}EXCEPTLog    Cannot retrieve JSON due to invalid dataENDENDCreate a Booking at Restful Booker${booking_dates}    Create Dictionary    checkin=2022-12-31    checkout=2023-01-01${body}    Create Dictionary    firstname=Hans    lastname=Gruber    totalprice=200    depositpaid=false    bookingdates=${booking_dates}${response}    POST    url=https://restful-booker.herokuapp.com/booking    json=${body}${id}    Set Variable    ${response.json()}[bookingid]Set Suite Variable    ${id}${response}    GET    https://restful-booker.herokuapp.com/booking/${id}Log    ${response.json()}Should Be Equal    ${response.json()}[lastname]    GruberShould Be Equal    ${response.json()}[firstname]    HansShould Be Equal As Numbers    ${response.json()}[totalprice]    200Dictionary Should Contain Value     ${response.json()}    GruberDelete Booking${header}    Create Dictionary    Cookie=token\=${token}${response}    DELETE    url=https://restful-booker.herokuapp.com/booking/${id}    headers=${header}Status Should Be    201    ${response}*** Keywords ***
Authenticate as Admin${body}    Create Dictionary    username=admin    password=password123${response}    POST    url=https://restful-booker.herokuapp.com/auth    json=${body}Log    ${response.json()}${token}    Set Variable    ${response.json()}[token]Log    ${token}Set Suite Variable    ${token}

todo MVC

这是一个BDD的例子

*** Settings ***
Library    Browser
Library    String
Suite Setup    New Browser    browser=${BROWSER}    headless=${HEADLESS}
Test Setup    New Context    viewport={'width': 1920, 'height': 1080}
Test Teardown    Close Context
Suite Teardown    Close Browser*** Variables ***
${BROWSER}    chromium
${HEADLESS}    False*** Test Cases ***
Add Two ToDos And Check Items[Documentation]    Checks if ToDos can be added and ToDo count increases[Tags]    Add ToDoGiven ToDo App is openWhen I Add A New ToDo "Learn Robot Framework"And I Add A New ToDo "Write Test Cases"Then Open ToDos should show "2 items left"Add Two ToDos And Check Wrong Number Of Items[Documentation]    Checks if ToDos can be added and ToDo count increases[Tags]    Add ToDoGiven ToDo App is openWhen I Add A New ToDo "Learn Robot Framework"And I Add A New ToDo "Write Test Cases"Then Open ToDos should show "1 items left"Add ToDo And Mark Same ToDo[Tags]    Mark ToDoGiven ToDo App is openWhen I Add A New ToDo "Learn Robot Framework"And I Mark ToDo "Learn Robot Framework"Then Open ToDos should show "0 items left"Check If Marked ToDos are removedGiven ToDo App is openAnd I Added Two ToDosWhen I Mark One ToDoThen Open ToDos should show "1 item left"Split ToDosGiven ToDo App is openWhen I Add New ToDos "Learn Robot Framework&Write Test Cases&Sleep"Then Open ToDos should show "3 items left"Add A Lot Of TodosGiven ToDo App is openWhen I Add "100" ToDosThen Open ToDos should show "100 items left"Add A Lot Of Todos With WHILEGiven ToDo App is openWhen I Add "100" ToDos With WHILE LoopThen Open ToDos should show "100 items left"*** Keywords ***
ToDo App is openNew Page    https://todomvc.com/examples/react/I Add A New ToDo "${todo}"   Fill Text  .new-todo  ${todo}Press Keys  .new-todo  EnterI Add New ToDos "${todo}"IF  "&" in $todo@{todos}    Split String    ${todo}    separator=&FOR  ${item}  IN  @{todos}Fill Text  .new-todo  ${item}Press Keys  .new-todo  Enter ENDELSEFill Text  .new-todo  ${todo}Press Keys  .new-todo  EnterENDOpen ToDos should show "${text}"Get Text    span.todo-count    ==    ${text}I Mark ToDo "${todo}"Click    "${todo}" >> .. >> input.toggleI Added Two ToDosI Add A New ToDo "Learn Robot Framework"I Add A New ToDo "Write Test Cases"I Mark One ToDoClick    li:first-child >> input.toggleI Add "${count}" ToDosFOR    ${index}    IN RANGE    ${count}I Add A New ToDo "My ToDo Number ${index}"    ENDI Add "${count}" ToDos With WHILE Loop${x}=    Set Variable    ${0}WHILE  ${x} < ${count}${x}=    Evaluate    ${x} + 1I Add A New ToDo "My ToDo Number ${x}"END

相关文章:

  • ACM实训冲刺第十九天
  • Vue.js组件设计模式:构建可复用组件库
  • SQL Server2019安装步骤教程(图文)_最新教程
  • Gradient-checkpointing的原理
  • 将list对象里的某一个属性取出组成一个新的list
  • PyTorch深度学习快速入门——P1-P13
  • 【python006】miniconda3环境搭建(非root目录,最近更新中)
  • Windows Presentation Foundation(WPF)要点总结
  • 大数据之Hive函数大全
  • 阿里云数据库 SelectDB 版全面商业化,开启现代化实时数据仓库的全新篇章
  • 工具方法 - 如何在网上找资料
  • 领导VS管理:技术团队掌舵者的双重角色解析
  • 贪心-leetcode402.移掉 K 位数字-XMUOJ符文序列
  • 算法思想汇总
  • 这样的直男程序员,活该你单身一万年!
  • 2017-09-12 前端日报
  • Docker 笔记(2):Dockerfile
  • es6
  • golang中接口赋值与方法集
  • Java,console输出实时的转向GUI textbox
  • Java到底能干嘛?
  • jQuery(一)
  • Laravel 中的一个后期静态绑定
  • Redis 懒删除(lazy free)简史
  • STAR法则
  • 百度贴吧爬虫node+vue baidu_tieba_crawler
  • 第2章 网络文档
  • 关于 Linux 进程的 UID、EUID、GID 和 EGID
  • 解析 Webpack中import、require、按需加载的执行过程
  • 开年巨制!千人千面回放技术让你“看到”Flutter用户侧问题
  • 译米田引理
  • 【运维趟坑回忆录 开篇】初入初创, 一脸懵
  • gunicorn工作原理
  • ​​​【收录 Hello 算法】10.4 哈希优化策略
  • ‌分布式计算技术与复杂算法优化:‌现代数据处理的基石
  • #QT(TCP网络编程-服务端)
  • (1)(1.9) MSP (version 4.2)
  • (12)目标检测_SSD基于pytorch搭建代码
  • (Arcgis)Python编程批量将HDF5文件转换为TIFF格式并应用地理转换和投影信息
  • (八)Flink Join 连接
  • (代码示例)使用setTimeout来延迟加载JS脚本文件
  • (二)换源+apt-get基础配置+搜狗拼音
  • (生成器)yield与(迭代器)generator
  • (算法)大数的进制转换
  • (算法)前K大的和
  • (原+转)Ubuntu16.04软件中心闪退及wifi消失
  • (转)利用ant在Mac 下自动化打包签名Android程序
  • .NET 3.0 Framework已经被添加到WindowUpdate
  • .NET Core 实现 Redis 批量查询指定格式的Key
  • .NET delegate 委托 、 Event 事件,接口回调
  • .py文件应该怎样打开?
  • /run/containerd/containerd.sock connect: connection refused
  • [@Controller]4 详解@ModelAttribute
  • [2023-年度总结]凡是过往,皆为序章
  • [8481302]博弈论 斯坦福game theory stanford week 1