RobotFrameWork基础一

2023-02-14,

1.变量:

作用域:
    Set Global Variables:设定全局级变量
    Set Suite Variables: 设定Test Suite 级变量
              Set Test Variable:设定Test Case级变量
          定义:

脚本中使用 Set Variable 定义变量
            普通变量:${}
            list变量:@{},也可以使用 Creat List 关键字创建List变量

    @{list1}    Set Variable     1     2    3     4
Log Many @{list1} @{list2} Create List a b c
Log Many @{list2}

字典:&{}

    &{dic}    Create Dictionary     name=Jack    age=18     Job=Student
Log ${dic} #输出整个字典
Log Many &{dic} # 输出字典里的值
${name} Get From Dictionary ${dic} name
Log ${name}
Log ${dic}[age]
Log ${dic.Job}

2.Settings

  Documention:add suite description

Suite Up:before run  the suite,  keyword below the suite first

Suite Teardown: when the suite finished, run the keyword below the suite

Test Setup:before the case start,run the keyword

Test Teardown:when the case finished,run the keyword

Test  Template:测试用例模板,指定某个关键字为这个测试套件下所有测试用例模板,之后所有用例传参只需要 填写该关键字即可

Test  Timeout:设置suite下每条case超时时间,超过该时间则失败停止运行

Force Tags:force  to suite and add tag label to the cases

Default Tags: add default tags for the cases [suite]

Library:import library

Resource:import resource

3.if,for结构

testif
${num1} Set Variable 5
${num2} Set Variable 1
Run Keyword If ${num1}>100 Log num1>100
... ELES IF ${num2}>0 Log num2>0
... ELSE Log num1不大于100 and mun2 也不大于0
testfor
@{list} Set Variable a b c d
FOR ${i} IN @{list}
Log To Console ${i} END

TestCase03
${a} Create List 1 2 3 4
${b} Create List 11 22 33 44
@{listtest} Create List ${a} ${b}
FOR ${li} IN @{listtest}
Log To Console ${li}
嵌套循环 @{li} END *** Keywords ***
嵌套循环
[Arguments] @{list}
FOR ${i} IN @{list}
Log To Console ${i} END
test for in range
FOR ${i} IN RANGE 1 10
Log To Console ${i} END
test for in enumerate
@{li} Create List a b c d
FOR ${index} ${element} IN ENUMERATE @{li}
Log ${index}: ${element} END
TestCase04
FOR ${index} ${name} ${n} ${m} IN ENUMERATE cat 猫 12 dog 狗 9
Log ${index}-${name}-${n}-${m} END
test for  in zip
@{list} Create List 1 2 3 4
${c} Create List a b c d
FOR ${number} ${char} IN ZIP ${list} ${c}
Log ${list} - ${c} END

3.列表变量和元素获取

testcase06
@{list} Create List 1 2 3 4
${len} Get Length ${list}
Log To Console ${len}
FOR ${value} IN @{list}
Log ${value}
END
Log To Console ${list[0]}
Log To Console ${list}[0]
# Log To Console @{list}[0] #错误写法 取值要用$
${li} Set Variable 1 3 5 7
Log To Console ${li}[0]

引入外部变量:

引入单值变量:--variable(-v) name:value ,  name对应的是${}变量名,value对应的是值。--escape可以转义特殊字符串

引入外部变量文件:--variablefile(-V)

example:    

--variable Name:Jack

--variable  --escape    quot:Q   --escape  space:_

--variablefile  path/to/variables.py

RobotFrameWork基础一的相关教程结束。

《RobotFrameWork基础一.doc》

下载本文的Word格式文档,以方便收藏与打印。