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

2024-05-27 02:04

本文主要是介绍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

这篇关于RobotFramework测试框架(1)--官网示例的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1006217

相关文章

CSS will-change 属性示例详解

《CSSwill-change属性示例详解》will-change是一个CSS属性,用于告诉浏览器某个元素在未来可能会发生哪些变化,本文给大家介绍CSSwill-change属性详解,感... will-change 是一个 css 属性,用于告诉浏览器某个元素在未来可能会发生哪些变化。这可以帮助浏览器优化

C++中std::distance使用方法示例

《C++中std::distance使用方法示例》std::distance是C++标准库中的一个函数,用于计算两个迭代器之间的距离,本文主要介绍了C++中std::distance使用方法示例,具... 目录语法使用方式解释示例输出:其他说明:总结std::distance&n编程bsp;是 C++ 标准

前端高级CSS用法示例详解

《前端高级CSS用法示例详解》在前端开发中,CSS(层叠样式表)不仅是用来控制网页的外观和布局,更是实现复杂交互和动态效果的关键技术之一,随着前端技术的不断发展,CSS的用法也日益丰富和高级,本文将深... 前端高级css用法在前端开发中,CSS(层叠样式表)不仅是用来控制网页的外观和布局,更是实现复杂交

C#使用SQLite进行大数据量高效处理的代码示例

《C#使用SQLite进行大数据量高效处理的代码示例》在软件开发中,高效处理大数据量是一个常见且具有挑战性的任务,SQLite因其零配置、嵌入式、跨平台的特性,成为许多开发者的首选数据库,本文将深入探... 目录前言准备工作数据实体核心技术批量插入:从乌龟到猎豹的蜕变分页查询:加载百万数据异步处理:拒绝界面

用js控制视频播放进度基本示例代码

《用js控制视频播放进度基本示例代码》写前端的时候,很多的时候是需要支持要网页视频播放的功能,下面这篇文章主要给大家介绍了关于用js控制视频播放进度的相关资料,文中通过代码介绍的非常详细,需要的朋友可... 目录前言html部分:JavaScript部分:注意:总结前言在javascript中控制视频播放

Java中StopWatch的使用示例详解

《Java中StopWatch的使用示例详解》stopWatch是org.springframework.util包下的一个工具类,使用它可直观的输出代码执行耗时,以及执行时间百分比,这篇文章主要介绍... 目录stopWatch 是org.springframework.util 包下的一个工具类,使用它

Spring Boot 3.4.3 基于 Spring WebFlux 实现 SSE 功能(代码示例)

《SpringBoot3.4.3基于SpringWebFlux实现SSE功能(代码示例)》SpringBoot3.4.3结合SpringWebFlux实现SSE功能,为实时数据推送提供... 目录1. SSE 简介1.1 什么是 SSE?1.2 SSE 的优点1.3 适用场景2. Spring WebFlu

springboot security快速使用示例详解

《springbootsecurity快速使用示例详解》:本文主要介绍springbootsecurity快速使用示例,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝... 目录创www.chinasem.cn建spring boot项目生成脚手架配置依赖接口示例代码项目结构启用s

golang 日志log与logrus示例详解

《golang日志log与logrus示例详解》log是Go语言标准库中一个简单的日志库,本文给大家介绍golang日志log与logrus示例详解,感兴趣的朋友一起看看吧... 目录一、Go 标准库 log 详解1. 功能特点2. 常用函数3. 示例代码4. 优势和局限二、第三方库 logrus 详解1.

SpringBoot实现MD5加盐算法的示例代码

《SpringBoot实现MD5加盐算法的示例代码》加盐算法是一种用于增强密码安全性的技术,本文主要介绍了SpringBoot实现MD5加盐算法的示例代码,文中通过示例代码介绍的非常详细,对大家的学习... 目录一、什么是加盐算法二、如何实现加盐算法2.1 加盐算法代码实现2.2 注册页面中进行密码加盐2.