zoukankan      html  css  js  c++  java
  • Robot Framework常用关键字

    虽然通过RIDE提供“填表”一样的写测试用例的方式。但它却支持强大的关键字功能,以及可以开发关键字的扩展能力。

    Comment

    注释功能,也可以使用python中的"#"

    Comment 注释
    #注释

    log

    打印。类似于print

    log Hello World

    set variable

    定义变量

    ${a} set variable Hello World!!!
    log ${a}

    catenate

    连接对象

    ${a} catenate hello world
    log ${a}

    SEPARATOR

    对多个连接进行分割(必须大写)

    ${a} catenate SEPARATOR=, hello world
    log ${a}

    create list

    创建列表

    ${a} create list a b c
    log ${a}

    通过@{}定义列表

    必须使用 log many 打印

    @{a} create list a b c
    log many @{a}

    get time

    获取当前时间

    ${a} get time
    log ${a}

    sleep

    设置休眠时间

    ${a} get time
    sleep 5
    ${a} get time

    run keyword if

    通过该语句可以编写if分支语句

    ${a} set variable 59
    run keyword if ${a}>=90 log 优秀
    ... ELSE IF ${a}>=60 and ${a}<90 log 一般
    ... ELSE log

    :FOR

    实现循环

    :FOR ${i} IN RANGE 10
    log ${i}

    列表遍历

    @{lista} create list a b c
    :FOR ${a} in @{lista}
    log ${a}

    Exit For Loop If

    退出循环的判断语句

    @{lista} create list a b c
    :FOR ${a} IN @{lista}
    exit for loop if '${a}'=='b'
    log ${a}

    Evaluate

    执行python中的方法

    ${a} Evaluate random.randint(1000,9999) random
    log ${a}

    Import Library

    导入标准和第三方模块或框架。比如调用unittest单元测试框架

    Import Library unittest

    导入外部py文件

    Import Library c:/test.py
    ${sum} add 3 4
    log ${sum}
    Import Library c:/test.py
    ${a} Evaluate int(4)
    ${b} Evaluate int(5)
    ${sum} add ${a} ${b}
    log ${sum}

    Take Screenshot

    截取当前屏幕,Screenshot库为robot framework的标准类库,需手动加载

    字典

    Collections库:该库为Robot Framework标准类库,它提供的关键字主要用于列表、索引、字典的处理。需要手动加载。

    Create Dictionary

    创建字典

    ${dict} Create Dictionary sname Luffy age 19

    Get Dictionary Items

    获取字典中的key和value

    | ${item} | Get Dictionary Items | ${dict} |
    | log | ${item} ||

    Get Dictionary Keys

    获取字典中的key

    ${keys} Get Dictionary keys ${dict}
    log ${keys}

    Get Dictionary Values

    获取字典中的value

    ${values} Get Dictionary Values ${dict}
    log ${values}

    Get From Dictionary

    根据key获取对应的value

    ${a} Get From Dictionary ${dict} sname
    log ${a}
  • 相关阅读:
    bzoj3237[Ahoi2013] 连通图
    bzoj3075[Usaco2013]Necklace
    bzoj1876[SDOI2009] SuperGCD
    bzoj3295[Cqoi2011] 动态逆序对
    BestCoder#86 E / hdu5808 Price List Strike Back
    bzoj2223[Coci 2009] PATULJCI
    bzoj2738 矩阵乘法
    poj 1321 -- 棋盘问题
    poj 3083 -- Children of the Candy Corn
    poj 2488 -- A Knight's Journey
  • 原文地址:https://www.cnblogs.com/TD1900/p/12072598.html
Copyright © 2011-2022 走看看