Robot学习之路(一)
| 基础语法(这里包括导包,定义变量,定义用例,基本的数据结构用法,分支结构) |
主要介绍Robot的一些基本用法,所有的语法注释已经写在了代码里面
# Setting 类似于python中的模块导入功能,这里引入demo.py这个模块
*** Setting ***
Library demo.py
Library OperatingSystem
Library String
# resource这个是导入某个robot文件,导入后就可以使用对应robot的keyword了
Library demo.py
Library String
#resource
*** Variables ***
# 这里可以定义一些全局变量
${test_var} 50
*** Test Cases ***
# 这里写测试用例
# 执行python的函数测试(这里会调用当前目录下的demo.py文件,这个函数其实就是输出一个helloworld)
Example 1 执行模块函数,获取返回值,输出到console
${tmp} Set Variable hello_world
${remove} Remove String ${tmp} _
log to console 这是删除后的变量: ${remove}
# robot自带的变量运算测试
Example 2
# [Arguments] ${} ${} 这里表示该用例执行的时候需要接收两个变量作为入参
${a} = Evaluate 1+2
${b} = Convert To Integer 3
Should Be Equal ${a} ${b}
# 执行系统功能(还不是很清楚)
Example 3
${out} = Run ls
# if else的使用(关键字就是 Run Keyword If 条件 LOG[类似于print] 语句,Set Variable 是设置一个变量的关键字)
Example 4 大于0
${rc} = Set Variable 2
Run Keyword If ${rc} == 0 LOG "等于0"
... ELSE IF ${rc} > 0 LOG "大于0"
... ELSE LOG "小于0"
Example 5 小于0
${rc} = Set Variable -1
Run Keyword If ${rc} == 0 LOG "等于0"
... ELSE IF ${rc} > 0 LOG "大于0"
... ELSE LOG "小于0"
Example 6 等于0
${rc} = Set Variable 0
Run Keyword If ${rc} == 0 LOG "等于0"
... ELSE IF ${rc} > 0 LOG "大于0"
... ELSE LOG "小于0"
Example 7
${str2} = Set Variable hello
Should Be True '${str2}' == 'hello'
Example 8 相等断言
${str1} = Catenate Hello World
Should Be Equal As Strings ${str1} Hello World
${str1} = Replace String ${str1} Hello Hi
Should Be Equal ${str1} Hi World
Example 9 包含断言
${temp1} Set Variable English
Should contain ${temp1} lish
Example 10 不包含断言
${temp2} Set Variable English
Should not contain ${temp2} test
Example 11 是否为空
${var1} Set Variable hello
Should Not Be Empty ${var1}
Example 12 以xx字符开始
${var2} Set Variable hello
Should Start With ${var2} hel
Example 13 是否为整形
${var3} Set Variable 25
Should Not Be Equal As Integers ${var3} 26
Example 14 列表创建
@{list_a} Create List 1 2 3
LOG ${list_a}
LOG to console ''
LOG to console ${list_a[0]}
LOG to console ${list_a[1]}
LOG to console ${list_a[2]}
Example 15 列表取值
LOG ''
Example 16 列表判断
LOG ''
Example 17 字典创建
${dict_a} create dictionary a=1 b=2 c=3
LOG to console ${dict_a}
LOG to console a= ${dict_a['a']}
LOG to console b= ${dict_a['b']}
LOG to console c= ${dict_a['c']}
Example 18 字典取值
${dict_a} create dictionary a=1 b=2 c=3
LOG to console a= ${dict_a['a']}
LOG to console b= ${dict_a['b']}
LOG to console c= ${dict_a['c']}