robotframework支持的文件格式
HTML
TSV
Plain TEXT
reStructuredText
后文將以 Plain TEXT格式囊蓝,以“空格”分割王浴,以“.robot”為文件后綴的方式來(lái)進(jìn)行相關(guān)說(shuō)明
robotframework目錄文件結(jié)構(gòu)
robotframework是以project為單位進(jìn)行管理的
一個(gè)project可以包含多個(gè)Test Suite
一個(gè)Test Suite可以包含多個(gè)測(cè)試用例
一個(gè)Test Suite有四部分組成:Settings谊迄、Variables哮独、Test Cases仍稀、Keywords
如何去執(zhí)行這些腳本:
1、執(zhí)行整個(gè)項(xiàng)目所有用例,pybot 項(xiàng)目路徑技潘,例如:
pybot D:\robot
2遥巴、執(zhí)行某個(gè)suite用例,pybot suite路徑享幽,例如:
pybot D:\robot\testsuit.txt
3铲掐、執(zhí)行某個(gè)測(cè)試用例,pybot –測(cè)試用例名 in 該測(cè)試用例所在suite值桩,例如
pybot --testcase1_login in D:\robot\testsuit.txt
4摆霉、將測(cè)試結(jié)果輸出到固定路徑,pybot –outputdir 報(bào)告路徑 用例路徑奔坟,例如:
pybot --ouputdir D:\ropot D:robot\testsuit.txt
5携栋、執(zhí)行某個(gè)tag的測(cè)試用例,pybot –include [tag name] [項(xiàng)目路徑]咳秉,例如:
pybot --include nomal D:\robot
查看報(bào)告文件
用例執(zhí)行完畢后會(huì)生成三個(gè)文件分別是:log.html婉支、output.xml、report.html
output.xml:記錄的測(cè)試結(jié)果是XML文件澜建,根據(jù)特定的需要可以編寫腳本讀取XML文件并生成特定的測(cè)試報(bào)告
log.html:會(huì)記錄Robotframework運(yùn)行的每一步操作向挖,主要用于編寫測(cè)試腳本的過(guò)程查看
report,html:為測(cè)試報(bào)告蝌以,整理性的展示測(cè)試用例的運(yùn)行情況
整理結(jié)構(gòu)如下:
總體結(jié)果及關(guān)鍵字說(shuō)明
*** Settings ***
Documentation 這個(gè)是當(dāng)前Test Suite說(shuō)明文字
Library 當(dāng)前Test Suite需要使用的庫(kù)
Resource 當(dāng)前Test Suite需要加載使用的資源,可能是參數(shù)也可能是用例文件
Metadata 定義元數(shù)據(jù)
Variables 引用變量文件
Suite Setup Test Suite執(zhí)行前的動(dòng)作
Suite Teardown Test Suite執(zhí)行后的動(dòng)作
Test Setup Test Case執(zhí)行前的動(dòng)作
Test Teardown Test Case執(zhí)行后的動(dòng)作
Force Tags Test Suite下的所有測(cè)試用例都會(huì)被打上這個(gè)tag
Default Tags Test Suite的用例如果沒(méi)有打上tag何之,就會(huì)用這個(gè)默認(rèn)tag跟畅,如果打了tag,就會(huì)用自己的tag
Test Timeout 設(shè)置每一個(gè)測(cè)試用例的超時(shí)時(shí)間帝美,只要超過(guò)這個(gè)時(shí)間就會(huì)失敗碍彭,并停止案例運(yùn)行
... 這是防止某些情況導(dǎo)致案例一直卡住不動(dòng),也不停止也不是失敗
Test Template 數(shù)據(jù)驅(qū)動(dòng)模板(很有用的一個(gè)參數(shù))
*** Variables ***
${SCALAR_VARS} 創(chuàng)建scalar參數(shù)
@{LIST_VARS} 創(chuàng)建list參數(shù)
&{DICT_VARS} a=創(chuàng)建dictionary參數(shù)
*** Test Cases ***
Test_01
[Documentation] 測(cè)試用例說(shuō)明……
[Template] 數(shù)據(jù)驅(qū)動(dòng)模板悼潭,每條用例只有一個(gè)模板
[Tags] 測(cè)試用例標(biāo)簽
[Setup] 測(cè)試用例執(zhí)行前的動(dòng)作
[Teardown] 測(cè)試用例執(zhí)行后的動(dòng)作
[Timeout] 測(cè)試用例的超時(shí)時(shí)間
My Keyword One
Test_02
[Documentation] 庇忌。。舰褪。
[Template] 皆疹。。占拍。
[Tags] 略就。。晃酒。
[Setup] 表牢。。贝次。
[Teardown] 崔兴。。蛔翅。
[Timeout] 敲茄。。山析。
My Keyword Two
*** Keywords ***
My Keyword One
[Documentation] 關(guān)鍵字描述
[Arguments] 自定義參數(shù)設(shè)置
[Return] 將返回值拋出
[Timeout] 關(guān)鍵字流程執(zhí)行超時(shí)時(shí)間
[Tags] 標(biāo)簽
[Teardown] 關(guān)鍵字流程結(jié)束動(dòng)作
log ${SCALAR_VARS}
log Mang @{LIST_VARS}
log ${DICT_VARS}
My Keyword Two
log ${SCALAR_VARS}
log Mang @{LIST_VARS}
log ${DICT_VARS}
下面是幾個(gè)簡(jiǎn)單的案例:
practice_setup_and_teardown.robot
*** Settings ***
Documentation test
Suite Setup suitestart
Suite Teardown suitestop
Test Setup testsetup
Test Teardown teststop
*** Variables ***
${a} hello world 1
$堰燎 hello world 2
*** Test Cases ***
testcase1
[Documentation] testcase1
log ${a}
testcase2
log $
*** Keywords ***
suitestart
Log suitstart
suitestop
Log suitstop
testsetup
Log teststart
teststop
Log teststop
practice_scalar.robot
*** Settings ***
Documentation RobotFramework腳本的scalar標(biāo)量練習(xí)
Force Tags robot-3.0
Default Tags owner-damao
*** Variables ***
# 創(chuàng)建scalar變量
${NAME} Robot Framework
${VERSION}= 3.0
${ROBOT} ${NAME} ${VERSION}
${NULL_VAR} # 空字符串被賦值給了${NULL_VAR}
${EXAMPLE} This value is joined together with a space
... 1122333333333333333333333333333333
${LONG_WORDS} 1111111111111111
# 創(chuàng)建列表變量
@{NAMES} Matti Teppo
@{NAMES2} @{NAMES} Seppo
@{NOTHING}
@{MANY} one two three four
... five six seven
# 創(chuàng)建字典變量
&{USER 1} name=Matti address=xxx phone=123
&{USER 2} name=Teppo address=yyy phone=456
# &{MANY} first=1 second=${2} ${3}=thirds
&{EVEN MORE} first=override empty=
... =empty key\=here=value
*** Test Cases ***
測(cè)試打印scalar變量
[Documentation] 打印scalar變量
To Test Scalar
*** Keywords ***
[Documentation] 創(chuàng)建關(guān)鍵字
To Test Scalar
[Documentation] 打印標(biāo)量
log ${NAME}
log ${ROBOT}
log ${NULL_VAR}
log ${EXAMPLE}
log ${LONG_WORDS}
practice_List.robot
*** Settings ***
Documentation RobotFramework腳本"列表"參數(shù)的練習(xí)
Force Tags robot-3.0
Default Tags owner-damao
*** Variables ***
@{list_data} 1 2 3 4 5
@{list_data2} a b c d e f
... q w e # 列表元素太長(zhǎng)時(shí)使用... 分割
*** Test Cases ***
test_01
[Documentation] 打印列表數(shù)據(jù)
Print List Variables
test_02
[Documentation] 獲取列表的長(zhǎng)度
Get List Length
*** Keywords ***
Print List Variables
[Documentation] 打印列表數(shù)據(jù)
log Many @{list_data}
log @{list_data}[2]
log Many @{list_data2} # 打印列表元素需要使用到log Many
log @{list_data2}[3]
Get List Length
[Documentation] 獲取列表的長(zhǎng)度
${length} BuiltIn.Get Length ${list_data2} # 在獲取列表的長(zhǎng)度時(shí)需要注意使用${列表參數(shù)}
log ${length}
practice_dict.robot
*** Settings ***
Documentation RobotFramework腳本“字典”參數(shù)的練習(xí)
Force Tags robot-3.0
Default Tags owner-damao
*** Variables ***
&{dict_data} a=b e=w y=1 asd=123
&{dict_data1} a=1 b=2 c=3 d=4
... r=7 u=90
*** Keywords ***
Print Dictionary Data
[Documentation] 打印字典數(shù)據(jù)
log ${dict_data}
log &{dict_data}[a]
log Many &{dict_data}[a] &{dict_data1}[u]
log ${dict_data1}
*** Test Cases ***
Test_01
[Documentation] 測(cè)試打印字典數(shù)據(jù)
Print Dictionary Data