Robot Framework 关键字操作实例

一、      百度搜索,进入官网,点击绿色框http://robotframework.org/

 

二、点击用户操作手册

 

三、第一个内置built-in,点击View

 

四、

4.1 RF变量不能有空和空格的普通输入

特殊的字符:内置变量

空:${EMPTY}

空格:${SPACE}

4.2数据类型,格式

数(int): ${数值}

字符串(str):str(‘内容’)

4.3关键字汇总

Set Variable:只是简单复制,后面写什么是什么

Examples:

${hi} =

Set Variable

Hello, world!

   

${hi2} =

Set Variable

I said: ${hi}

   

${var1}

${var2} =

Set Variable

Hello

world

@{list} =

Set Variable

${list with some items}

   

${item1}

${item2} =

Set Variable

${list with 2 items}

 

Evaluate:(可参与运算)

Examples (expecting ${result} is 3.14):

${status} =

Evaluate

0 < ${result} < 10

# Would also work with string '3.14'

${status} =

Evaluate

0 < $result < 10

# Using variable itself, not string representation

${random} =

Evaluate

random.randint(0, sys.maxint)

modules=random, sys

${ns} =

Create Dictionary

x=${4}

y=${2}

${result} =

Evaluate

x*10 + y

namespace=${ns}

汇总:

 

random.randint(0,5) :范围内取随机数

#取随机值

 

 

 

${randomInt}

Evaluate

random.randint(0,5)

modules=random

log

${randomInt}

 

 

 

 

Comment:备注

 

Convert To Boolean     :转成bool型,True and False,类似于python中bool()

对于数字:0是False,其余是True

对于字符串:空是False,其余是True,空格也是True

 

结果是:False

Convert To Number :转换成数或小数

Examples:

${result} =

Convert To Number

42.512

 

# Result is 42.512

${result} =

Convert To Number

42.512

1

# Result is 42.5

${result} =

Convert To Number

42.512

0

# Result is 43.0

${result} =

Convert To Number

42.512

-1

# Result is 40.0

 

Get Length: 获取长度

Examples:

${length} =

Get Length

Hello, world!

 

Should Be Equal As Integers

${length}

13

 

@{list} =

Create List

Hello,

world!

${length} =

Get Length

${list}

 

Should Be Equal As Integers

${length}

2

 

 

Get Time :获取时间

Examples (expecting the current local time is 2006-03-29 15:06:21):

${time} =

Get Time

     

${secs} =

Get Time

epoch

   

${year} =

Get Time

return year

   

${yyyy}

${mm}

${dd} =

Get Time

year,month,day

@{time} =

Get Time

year month day hour min sec

   

${y}

${s} =

Get Time

seconds and year

 

 

 

Log:打印

运算符:

Should Be Empty:是否是空;如果是空,正常执行;不为空,执行错误

 

执行结果:None

Should Be Equal:是否相等;如果相等,正常执行;不相等,执行错误

 

执行结果:正常执行

Should Be Equal As Numbers:是否相等,取小数点后几位(四舍五入)

如果对象在转换成实数后是不相等的,则失败。

 

执行结果:正常执行

Should Be Equal As Strings:字符串是否相等 相等,正常执行;不相等,执行报错

如果对象在转换为字符串后不相等,则失败。

 

执行结果:正常执行

Should Be True  :是否为真

Examples:

Should Be True

${rc} < 10

 

Should Be True

'${status}' == 'PASS'

# Strings must be quoted

Should Be True

${number}

# Passes if ${number} is not zero

Should Be True

${list}

# Passes if ${list} is not empty

 

控制语句:

 

数据类型:数、字符串(相加、替换、查找)、list、dict

 

函数:

 

 

 

作业:产生一个随机数(0~100),一直猜,猜中结束,操作提示 > <

用到的语法:变量、random、if判断、for循环

 

posted @ 2018-01-03 16:57  liuhuanv  阅读(417)  评论(0编辑  收藏  举报