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

相关文章

python实现pdf转word和excel的示例代码

《python实现pdf转word和excel的示例代码》本文主要介绍了python实现pdf转word和excel的示例代码,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价... 目录一、引言二、python编程1,PDF转Word2,PDF转Excel三、前端页面效果展示总结一

在MyBatis的XML映射文件中<trim>元素所有场景下的完整使用示例代码

《在MyBatis的XML映射文件中<trim>元素所有场景下的完整使用示例代码》在MyBatis的XML映射文件中,trim元素用于动态添加SQL语句的一部分,处理前缀、后缀及多余的逗号或连接符,示... 在MyBATis的XML映射文件中,<trim>元素用于动态地添加SQL语句的一部分,例如SET或W

Redis延迟队列的实现示例

《Redis延迟队列的实现示例》Redis延迟队列是一种使用Redis实现的消息队列,本文主要介绍了Redis延迟队列的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习... 目录一、什么是 Redis 延迟队列二、实现原理三、Java 代码示例四、注意事项五、使用 Redi

在Pandas中进行数据重命名的方法示例

《在Pandas中进行数据重命名的方法示例》Pandas作为Python中最流行的数据处理库,提供了强大的数据操作功能,其中数据重命名是常见且基础的操作之一,本文将通过简洁明了的讲解和丰富的代码示例,... 目录一、引言二、Pandas rename方法简介三、列名重命名3.1 使用字典进行列名重命名3.编

Python使用Colorama库美化终端输出的操作示例

《Python使用Colorama库美化终端输出的操作示例》在开发命令行工具或调试程序时,我们可能会希望通过颜色来区分重要信息,比如警告、错误、提示等,而Colorama是一个简单易用的Python库... 目录python Colorama 库详解:终端输出美化的神器1. Colorama 是什么?2.

Go Gorm 示例详解

《GoGorm示例详解》Gorm是一款高性能的GolangORM库,便于开发人员提高效率,本文介绍了Gorm的基本概念、数据库连接、基本操作(创建表、新增记录、查询记录、修改记录、删除记录)等,本... 目录1. 概念2. 数据库连接2.1 安装依赖2.2 连接数据库3. 数据库基本操作3.1 创建表(表关

Python视频剪辑合并操作的实现示例

《Python视频剪辑合并操作的实现示例》很多人在创作视频时都需要进行剪辑,本文主要介绍了Python视频剪辑合并操作的实现示例,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习... 目录介绍安装FFmpegWindowsMACOS安装MoviePy剪切视频合并视频转换视频结论介绍

python多进程实现数据共享的示例代码

《python多进程实现数据共享的示例代码》本文介绍了Python中多进程实现数据共享的方法,包括使用multiprocessing模块和manager模块这两种方法,具有一定的参考价值,感兴趣的可以... 目录背景进程、进程创建进程间通信 进程间共享数据共享list实践背景 安卓ui自动化框架,使用的是

SpringBoot基于MyBatis-Plus实现Lambda Query查询的示例代码

《SpringBoot基于MyBatis-Plus实现LambdaQuery查询的示例代码》MyBatis-Plus是MyBatis的增强工具,简化了数据库操作,并提高了开发效率,它提供了多种查询方... 目录引言基础环境配置依赖配置(Maven)application.yml 配置表结构设计demo_st

SpringCloud集成AlloyDB的示例代码

《SpringCloud集成AlloyDB的示例代码》AlloyDB是GoogleCloud提供的一种高度可扩展、强性能的关系型数据库服务,它兼容PostgreSQL,并提供了更快的查询性能... 目录1.AlloyDBjavascript是什么?AlloyDB 的工作原理2.搭建测试环境3.代码工程1.