*** Settings ***
Library DateTime #import datetime
Library String
Resource 资源文件.robot
Variables vars.py
Documentation 练习脚本,涉及变量和关键字应用
... Author:fyangq
... 时间:2020-06-28
Test Setup Log =======用例开始执行========
Test Teardown Log ========用例执行结束=======
Suite Setup Log =======测试套件开始执行======
Suite Teardown Log ======测试套件执行结束======
*** Variables ***
${hig}= Set Variable Hello,world!
@{listg}= 123 456 789
&{dictg}= name=eden age=${18} course=python
*** Test Cases ***
第一次使用robot获取当前时间
${date}= Get Current Date
#t Date date exclude_millis=yes date_format=%m.%d.%Y %H:%M
# Should Be Equal ${date.year} ${2020}
${str} Get Substring ${date} 0 10
Should Be Equal ${str} 2020-06-28
用例2
Should Be Equal 100 100
用例3
${count}= 两数求和1 100 100
${count}= 两数求和1 100
用例4-变量赋值
${hi}= Set Variable Hello,world!
@{list}= Create List 123 456 789
&{dict}= Create Dictionary name=eden age=${18} course=python
Log ${hi}
Log ${list[1]} #输出列表第二个元素
Log ${dict.name} #输出字典指定key的值
Log ${list}
Log ${dict}
用例5
Log ${hig}
Log ${listg[1]} #输出列表第二个元素
Log ${dictg.name} #输出字典指定key的值
Log ${listg}
Log ${dictg}
用例6-从变量文件中读取变量
Log ${my_hi}
Log ${my_list[1]} #输出列表第二个元素
Log ${my_dict["name"]} #输出字典指定key的值
Log ${my_list}
Log ${my_dict}
Log ${you_dict.school}
用例7-遍历列表
:FOR ${item} IN @{listg}
Log ${item}
#Exit For Loop If ${item}==456
Continue For Loop If ${item}==456
${len}= Get Length ${my_list}
:FOR ${index} IN RANGE ${len}
Log ${my_list[${index}]}
用例8-双层for循环-不支持2个for叠加
:FOR ${item} IN @{listg}
# Log ${item}
Exit For Loop If ${item}==777
内层循环
用例9-if判断
${rc}= Set Variable eden
Run Keyword If "${rc}"=="eden" Log BINGO
... ELSE Log error
${rc1}= Set Variable 44
${res}= Run Keyword If ${rc1}<0 Log 竟然是负分
... ELSE IF ${rc1}<60 Set Variable 不及格
... ELSE IF ${rc1}<80 Log 仍需努力
... ELSE Log 优秀
用例10-rf版的异常捕获
${passed}= Run Keyword And Return Status Log hello,rf
Run Keyword If ${passed} Log bingo
... ELSE Log Error!
#用户关键字-业务需要
*** Keywords ***
两数求和
[Arguments] ${num1} ${num2}=60
${sum}= Evaluate ${num1}+${num2}
[Return] ${sum}
内层循环
${len}= Get Length ${my_list}
:FOR ${index} IN RANGE ${len}
Log ${my_list[${index}]}