自动化测试之Robot Framework

RobotFramework学习02-基础关键字

2018-09-14  本文已影响129人  残阳夕露

RobotFramework学习笔记目录


本文包含内容:

  1. 基础关键字
  2. 基础关键字(高级用法)
  3. 内置关键字查询

关键字

关键字类似于python中的函数

访问某个网址(前提是已经打开过浏览器)(可在初始化中打开浏览器)

Go To    https://www.baidu.com

如果是字符串,需要加引号;数字不需要

# 示例
${str1}=  set variable  hello
Should Be True  $str1 == 'hello'
Should Be True  '${str1}' == 'hello'

${str1}=  convert to interger  20
Should Be True  ${str1} == 19
Should Be True  $str1 == 19

Library xxx.py 寻找路径同pyhon中选择模块的方法(path)

文档中import部分为导入文档时可使用的参数

# 例如导入SeleniumLibrary
Library    SeleniumLibrary    implicit_wait=10  # 修改等待时间

基础关键字

log就是python中的"print"
*** Test Cases ***
test case1
    log    robot framework
    log    python

log to console将信息打印到控制台(不会存储到log文件中)
test case1
    log to console    robot framework
    log to console    python
定义变量
*** Test Cases ***
test case2
    ${var}  set variable  test python
    log  ${var}
定义及展示列表
test case4
    ${hi}    Create List    hello    world
    log    ${hi}
    log many    @{hi}
连接对象
*** Test Cases ***
test case3
    ${hi}    Catenate    hello    world
    log    ${hi}
test case4
    ${hi}    Catenate    SEPARATOR=---    hello    world
    log    ${hi}
时间操作
test case4
    ${hi}    get time
    log to console    ${hi}
test case4
    ${t1}    get time
    sleep  5
    ${t2}    get time

基础关键字(高级用法)

if语句

注1:ELSE IFELSE 前面的三个点(…)
注2:ELSE IFELSE 必须大写

test case4
    ${hi}  set variable  90
    run keyword if   ${hi}>=90   log to console   优秀
    ...   ELSE IF     ${hi}>=80   log to console    良好
    ...   ELSE IF    ${hi}>=60   log to console    及格
    ...   ELSE   log to console   不及格
for循环

在Robot Framework中编写循环通过:FOR
循环内的语句必须以\开头

test case4
    :for  ${i}  in range   10
    \  log to console   ${i}
test case4
    ${abc}  create list  1  2  3   a
    :for  ${i}  in  @{abc}
    \  log to console  ${i}
强大的Evaluate

通过Evaluate可以使用 Python 语言中所提供的方法。

test case4
    ${d}  evaluate  random.randint(999,9999)   random
    log to console   ${d}

test case4
    ${d}  evaluate  int(4)
上一篇 下一篇

猜你喜欢

热点阅读