博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
简例s - Variables
阅读量:6648 次
发布时间:2019-06-25

本文共 3005 字,大约阅读时间需要 10 分钟。

1. Set Variable

定义:Returns the given values which can then be assigned to a variables.

示例1:

${a}    Set Variable    50

示例2:

${traffic_in_xpath}=    Set Variable    xpath=//table[@id='blocked_services_table']//td[text()='${service_name}']/parent::tr/td[4]${traffic_in_status}     Get Element Attribute     ${browser}     ${traffic_in_xpath}//input[@type='checkbox']@checked${traffic_in_checked}=    Run Keyword If    '${traffic_in_status}'=='None'    Set Variable    false    ELSE    Set Variable    true

 

2. Create List

定义:Returns a list containing given items.

示例1:

@{list}  Create List  a  b  c

示例2:

: FOR    ${index}    IN RANGE    5     \    # Verify the connection status    \    ${is_pass}    Run Keyword And Ignore Error    Should Match Regexp    ${result}    Connection.*succeeded!    \    # Verify the result    \    Run Keyword If    '@{is_pass}[0]'=='${expected_status}'    Exit For Loop

 

3. Evaluate  

定义:Evaluates the given expression in Python and returns the results.

示例1:

generate random ip address    [Arguments]    ${start}    ${stop}    [Documentation]    generate random IP address, such as 192.168.1.xxx    [Return]  ${r}    ${random}    Evaluate    random.randint(${start},${stop})    random    ${r}    Set Variable    192.168.1.${random} 

示例2:类型转换

${a}    Evaluate    int(4) ${b}    Evaluate    int(5)

示例3:结果运算

${ns} =    Create Dictionary    x=${4}    y=${2}${result}=    Evaluate    x*10 + y    namespace=${ns} Result:${ns} = {'x': 4, 'y': 2}${result} = 42

  

4. Get Variable Value

定义:

Returns variable value or default if the variable does not exist.

示例1:

*** Test Cases ***test case1 - Run Keyword If    ${a}    Set Variable    50    Run Keyword If    ${a}>=90    Log    优秀    ...    ELSE IF    ${a}>=70    Log    良好    ...    ELSE IF    ${a}>=60    Log    及格    ...    ELSE    Log    不及格          ${a_a}    Get Variable Value    ${a}    log    ${a_a} test case2 - Run Keyword Ignore Error    @{CAPTAINS}    Create List    Picard    Kirk    Archer    Run Keyword And Ignore Error    Should Be Empty    ${CAPTAINS}    Log    Reached this point despite of error        @{list}    Get Variable Value    @{CAPTAINS}    log    ${list}运行结果:Starting test: Rf Test.Helloworld.test case1 - Run Keyword If20180519 14:34:58.590 : INFO : ${a} = 5020180519 14:34:58.592 : INFO : 不及格20180519 14:34:58.594 : INFO : ${a_a} = 5020180519 14:34:58.594 : INFO : 50Ending test: Rf Test.Helloworld.test case1 - Run Keyword IfStarting test: Rf Test.Helloworld.test case2 - Run Keyword Ignore Error20180519 14:34:58.597 : INFO : @{CAPTAINS} = [ Picard | Kirk | Archer ]20180519 14:34:58.598 : INFO : Length is 320180519 14:34:58.599 : FAIL : '['Picard', 'Kirk', 'Archer']' should be empty.20180519 14:34:58.601 : INFO : Reached this point despite of error20180519 14:34:58.602 : INFO : @{list} = [ Picard | Kirk | Archer ]20180519 14:34:58.603 : INFO : ['Picard', 'Kirk', 'Archer']Ending test: Rf Test.Helloworld.test case2 - Run Keyword Ignore Error

  

 

转载于:https://www.cnblogs.com/studyddup0212/p/9060295.html

你可能感兴趣的文章
CloudStack4.1.1升级CloudPlatForm4.2.0实践手册
查看>>
Centos安装各种数据分析库,numpy,pandas,matplotlib,seaborn,scipy
查看>>
C#基础知识整理:C#类和结构(3)
查看>>
SharePoint Server 2010 初始化
查看>>
【我眼中的戴尔转型】(四)惠普之道,月亮的脸悄悄地在改变
查看>>
***S 2012 聚合函数 -- 指定分页示例
查看>>
直播疑难杂症排查(3)— 首开慢
查看>>
某公司机房成功搭建openssh server跳板服务器
查看>>
ADT在線互動教學
查看>>
PowerShell 添加 自定义的ScriptProperty 属性
查看>>
Shell一些例子
查看>>
MySQL 可优化的一些参数详解
查看>>
zabbix监控web页面,以及告警配置
查看>>
C#中传值调用和传引用调用的理解
查看>>
硬盘整数分区最精确地方法(转载)
查看>>
Oracle-压缩数据
查看>>
Exchange Server2010系列之十六:客户端访问方式
查看>>
crawler4j 爬爬知多少
查看>>
记录:Protocol Buffers(protobuf)在Java开发中使用
查看>>
关于Diablo3的历史和现状思考
查看>>