• 05:robotframework条件判断、初始化清除与evaluate


    01:条件判断

    • RF中用Run Keyword if  关键字做条件判断
    1. 条件表达式参数给python的eval函数
    2. run keyworld if ‘2019’ in $html  log to  console 内容
    • 参数放在下一行

    run keyword if  ‘2019’ in $html and  'UTC' in $html

    ...                        log to console    2019年的,UTC时间

    *** Test Cases ***
    测试1
            ${html}  getwebinfo
            #判断html是否包含对应信息
            run keyword if    '2020' in $html  log to console 今年是2020年

    02:ELSE分支

    run keyword if  '2019' in $html and 'UTC' in $html
    ...             log  to  console  
    2019年的,UTC时间
          ...    ELSE     log  to  console   
    不是2019年的时间

    ELSE  IF  参数

    run keyword  if  '2019' in $html and 'UTC' in $html
    ...          log to  console  
     2019年的,UTC时间
        ...   ELSE IF   '2019' in $html  log to console  
    2019年的
        ...   ELSE IF   'UTC'  in $html  log to  console  
    UTC时间
        ...   ELSE                       log  to  console  
    以上都不是

    03:循环里面的判断

    • Exit For  Loop  与 Continue  For  Loop
    *** Test Cases ***
    测试1
            FOR  ${i} IN RANGE  9999
                ${weigt}  get value from user   请输入你的体重
                run keyword if  $weight=='cont'   continue for loop
                run keyword if  $weight=='break'  exit for loop
                log to console   体重${weight}
                run keyword if  int($weight) >60  log to console  超重了要减肥
     
            END
    
     ##简写
    *** Test Cases ***
    测试1
            FOR  ${i} IN RANGE  9999
                ${weigt}  get value from user   请输入你的体重
                continue for loop if    $weight=='cont'
                exit for loop if  $weight=='break'
                log to console   体重${weight}
                run keyword if  int($weight) >60  log to console  超重了要减肥
    
            END

    04:collection 标准库

    官方文档介绍:collection是用来处理robotframework列表和字典的库

    • 针对List 和Diction 的处理
    • 创建并添加元素
    • 数字变量 ${1}  ${2}
    *** Settings ***
    Library   Collections
    
    *** Test Cases ***
    测试1
            ${list}=  create list   a   b   c
            Append To List    ${list}   hello  #增加
            remove from list  ${list}  0   #删除
            set List Value   ${list}  0  he  #替换
            log to console   ${list}

    05:Evaluate

    官方文档介绍:Evaluate是执行python表达式,并返回执行结果

    • 直接用python代码表达式来生成一个结果
    • ${var}=  set variable  ${890}

    完全可以写成

    ${var}= evaluate  890

    • 复杂的表达式

    ${var}= evaluate  ['hello']*10

    image.png

    由python文件函数,使用RF导入

     image.png

    我是kelly-凯莉 每天努力一点点,幸运就多一点点
  • 相关阅读:
    C/C++——二维数组与指针、指针数组、数组指针(行指针)、二级指针的用法
    C/C++——C语言数组名与指针
    C/C++——C语言跳出多重循环方法
    知识储备——国际象棋术语中英文对照
    C/C++——C语言库函数大全
    C/C++——C语言常用库函数
    C/C++——[05] 函数
    C/C++——[04] 语句
    C/C++——[03] 注释
    C/C++——[02] 运算符和表达式
  • 原文地址:https://www.cnblogs.com/kelly11/p/12696048.html
Copyright © 2020-2023  润新知