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

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/diannao/16422.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

Java开发大厂面试第17讲:MySQL 的优化方案有哪些?数据库设计、查询优化、索引优化、硬件和配置优化等

性能优化&#xff08;Optimize&#xff09;指的是在保证系统正确性的前提下&#xff0c;能够更快速响应请求的一种手段。而且有些性能问题&#xff0c;比如慢查询等&#xff0c;如果积累到一定的程度或者是遇到急速上升的并发请求之后&#xff0c;会导致严重的后果&#xff0c;…

字母异位词分组-力扣

首先想到的解法是调用上道题写好的 有效的字母异位词 函数&#xff0c;来对strs中的字符串进行两两判断&#xff0c;然后添加到不同的vector&#xff0c;但转眼一想这样写无疑过于麻烦。在想到上提另一种解法排序后&#xff0c;本题也可以采用排序的方法来做&#xff0c;遍历st…

变分自动编码器(VAE)深入理解与总结

本文导航 0 引言1 起源1.1 自编码器的任务定义1.2 自编码器存在的问题1.3 VAE的核心思路 2 VAE的建模过程2.1 VAE的任务定义2.2 真实分布 ϕ \phi ϕ是什么&#xff0c;为什么要逼近这个分布的参数&#xff0c;如何做&#xff1f;2.3 “重参数化&#xff08;Reparameterization…

互联网十万个为什么之 什么是Kubernetes(K8s)?

Kubernetes&#xff08;通常简称为K8s&#xff09;是一款用于自动部署、扩缩和管理容器化应用程序的开源容器编排平台。Kubernetes已发展为现代企业实现敏捷开发、快速迭代、资源优化及灵活扩展的关键技术组件之一。它拥有庞大的开源社区和丰富的生态系统。围绕Kubernetes已经形…

.lib .a .dll库互转

编译 mingw工具&#xff0c;gendef.exe转换dll为a&#xff0c;reimp转换lib为adlltool.exe --dllname python38.dll --def python38.def --output-lib libpython38.adlltool -k -d crypto.lib -l crypto.a 创作不易&#xff0c; 小小的支持一下吧&#xff01;

koa使用ws,scoket.io建立websocket连接,断开重连

1.使用ws建立socket连接&#xff0c;ws兼容性比socket.io要好一些 koa.js const Koa require(koa); // 引入 Koa 框架 const http require(http); // 引入 Node.js 的 http 模块 const { WebSocketServer } require(ws); // 引入 ws 模块中的 WebSocketServer const cors…

QT之常用控件

一个图形化界面当然需要有各种各样的控件&#xff0c;QT也不例外&#xff0c;在QT designer中就有提供各种各样的控件&#xff0c;用以开发图形化界面。 而想使用好一个QT控件&#xff0c;就需要了解这些控件。 QWidget 在QT中&#xff0c;所有控件都继承自 QWidget 类&…

推荐10款优秀的组件库(一)

1.Ant Desgin UI 网址&#xff1a; https://ant-design-mobile.antgroup.com/zh Ant Design - 一套企业级 UI 设计语言和 React 组件库 "Ant Design Mobile"是一个在线的移动端Web体验平台&#xff0c;让你探索移动端Web的体验极限。 添加图片注释&#xff0c;不…

622.设计循环队列

typedef struct {int* a;int head;int tail;int k; } MyCircularQueue;bool myCircularQueueIsEmpty(MyCircularQueue* obj); bool myCircularQueueIsFull(MyCircularQueue* obj);//初始化 MyCircularQueue* myCircularQueueCreate(int k) {MyCircularQueue* obj(MyCircularQue…

CSS3开发实践难点

目录 响应式设计与流体布局动画与交互性能优化CSS预处理器与后处理器CSS-in-JSCSS高级技巧视觉与滤镜效果工具与工作流实验性响应式设计与流体布局 媒体查询(M

.cc和.cpp文件的区别

在C编程中&#xff0c;文件扩展名为.cpp和.cc的文件实际上没有本质的区别&#xff0c;它们都用于存储C源代码。两种扩展名都可以用于编写C程序&#xff0c;并且在大多数情况下&#xff0c;它们可以互换使用。 一般来说&#xff0c;.cpp扩展名是最常见的用于C源代码文件的标准扩…

linux内核调试技巧四:gdb调试+vmlinux

vmlinux是个elf文件&#xff0c;它的符号表中包含了所有内核符号。 注意linux中很多文件是没有后缀的&#xff0c;比如我见到的这个elf文件的文件名是“vmlinux-3.10.62”&#xff0c;没有后缀。 既然是elf文件那就可以用 点击打开链接 里面的方法直接查看符号表。 要想看得…

SW 草图偏移 先预选

因为有些不能用链全部选,可以先框选要偏移的,再点偏移命令

探索python列表处理:偶数筛选的两种方法

新书上架~&#x1f447;全国包邮奥~ python实用小工具开发教程http://pythontoolsteach.com/3 欢迎关注我&#x1f446;&#xff0c;收藏下次不迷路┗|&#xff40;O′|┛ 嗷~~ 目录 一、引言 二、不使用列表生成式的偶数筛选 1. 读取输入列表 2. 筛选偶数 三、使用列表生…

重学java 46.集合 ① Collection集合

事常与人违&#xff0c;事总在人为 —— 24.5.26 集合 知识导航 1.集合的特点以及作用 2.使用collection接口中的方法 3.使用迭代器迭代集合 4.ArrayList以及LinkedList的使用 5.使用增强for遍历集合 一、单列集合框架的介绍 1.长度可变的容器&#xff1a;集合 2.集合的特点 a.…

每日一问-如何设置VS Code 中 Markdown粘贴图片的位置

VS Code内的markdown编辑器应该算是比较好用的&#xff0c;但是有一个问题一直困扰着我&#xff0c;就是在编辑markdown文件时&#xff0c;粘贴图片的位置问题。默认情况下&#xff0c;VS Code会将粘贴的图片放在markdown文件的同级目录下&#xff0c;这样会导致markdown文件的…

OSPF多区域组网实验(华为)

思科设备参考&#xff1a;OSPF多区域组网实验&#xff08;思科&#xff09; 技术简介 OSPF多区域功能通过划分网络为多个逻辑区域来提高网络的可扩展性和管理性能。每个区域内部运行独立的SPF计算&#xff0c;而区域之间通过区域边界路由器进行路由信息交换。这种划分策略适用…

three.js中使用CameraHelper来可视化调整阴影相机的范围

1. three.js中使用CameraHelper来可视化调整阴影相机的范围 光源 const directionLight new THREE.DirectionalLight(0xffffff, 1); directionLight.position.set(100, 60, 20); directionLight.castShadow true; scene.add(directionLight);设置计算阴影的范围 direction…

Unity3D MMORPG 主城角色动画控制与消息触发详解

Unity3D是一款强大的游戏开发引擎&#xff0c;它提供了丰富的功能和工具&#xff0c;使开发者能够轻松创建出高质量的游戏。其中&#xff0c;角色动画控制和消息触发是游戏开发中非常重要的一部分&#xff0c;它们可以让游戏角色表现出更加生动和多样的动作&#xff0c;同时也能…

构建智慧科技园区的系统架构:数字化驱动未来创新

随着科技的不断进步和数字化转型的加速推进&#xff0c;智慧科技园区已成为当今城市发展的重要组成部分。在智慧科技园区建设中&#xff0c;系统架构的设计和实施至关重要&#xff0c;对于提升园区管理效率、优化资源利用、促进创新发展具有重要意义。 一、智慧科技园区系统架构…