WAT的使用方法:
1.當(dāng)創(chuàng)建完project "Demo"后,在testcase文件夾下會(huì)創(chuàng)建一個(gè)Demo的文件夾,Demo文件夾下會(huì)出現(xiàn)如下的文件:conf.yaml,Demo.rb,Demo.yaml,ExpectedData.yaml,TestData.yaml
2.conf.yaml的作用
conf.yaml創(chuàng)建時(shí)為空,
conf.yaml文件是對(duì)config/conf.yaml文件的擴(kuò)展,在conf.yaml里可以自定義配置選項(xiàng),如果conf.yaml與config/conf.yaml的配置項(xiàng)相同,config/conf.yaml里的配置項(xiàng)則會(huì)被conf.yaml里的配置項(xiàng)覆蓋。
在測試方法里,即Demo.rb文件里的測試方法里,調(diào)用conf.yaml與config/conf.yaml里的配置項(xiàng)的方法為:ConfigData("配置項(xiàng)名稱")。
3.Demo.yaml的作用
Demo.yaml是存放頁面元素對(duì)象的文件。
Demo.yaml文件在初始時(shí)不為空,顯示了存放頁面元素對(duì)象的兩種方式。
第一種方式中,type是必填項(xiàng).parent結(jié)點(diǎn),如果有parent,則需加上,如沒有,則不加、。比如@ie.div(:class,"test").div(:index,1),示例為:
test1:
type: div
class: test
test2:
type: div
index: 1
parent: test1
test1沒有parent,所以不必要加上該結(jié)點(diǎn),test2有parent "test1",所以需要加上parent,value為test1。
第二種方式中,寫法為:
test2: div(:class,"test").div(:index,1)
我們?cè)陧?xiàng)目中,其實(shí)第二種方式用的比較多。
第三種方式,在Demo.yaml文件中沒有演示出來,用法是:(第三種方式配合第二種方式,這樣效果會(huì)更好)
test1: div(:class,"test")
test2: %test1%.div(:index,1)
在測試方法里,即Demo.rb文件里的測試方法里,調(diào)用Demo.yaml的頁面元素對(duì)象的方法為:AutoTest("test1"),AutoTest("test2").
4.TestData.yaml的作用
TestData.yaml是存放測試數(shù)據(jù)的文件,格式一定要嚴(yán)格按照文件中已定義好的格式
由于該框架是數(shù)據(jù)驅(qū)動(dòng)的模式,數(shù)據(jù)驅(qū)動(dòng)的概念是指腳本或測試方法根據(jù)配置的數(shù)據(jù)的條數(shù)來循環(huán)運(yùn)行,所以除common結(jié)點(diǎn)外,其它的結(jié)點(diǎn)是腳本中測試方法的名稱,比如在Demo.rb文件中有個(gè)test_Demo方法,所以在TestData.yaml的配置:
- test_Demo:
description: test for 123
inputValue: 123
- test_Demo:
description: test for 234
inputValue: 234
則test_Demo方法會(huì)運(yùn)行兩次,在腳本中用inputValue的值時(shí),第一次是123,第二次為234.
如果在TestData.yaml里的結(jié)點(diǎn)與Demo.rb文件中的測試方法名不一致,則會(huì)沒有測試方法被運(yùn)行。
TestData.yaml中的common結(jié)點(diǎn),是配置的測試方法中的數(shù)據(jù)的公共結(jié)點(diǎn),common結(jié)點(diǎn)里的數(shù)據(jù),在配置的測試方法中都可以被使用,如果測試方法中與common中存在相同的數(shù)據(jù),則common結(jié)點(diǎn)中的數(shù)據(jù)會(huì)被覆蓋。比如:test_Demo中的description的value值會(huì)覆蓋common中的description的value值。TestData.yaml文件中必須存在三個(gè)數(shù)據(jù)結(jié)點(diǎn):private,smoking,description。否則會(huì)報(bào)錯(cuò)。
private,smoking是兩種運(yùn)行模式,在config/conf.yaml中RunTimeModule的值如果為private,則會(huì)運(yùn)行private的值為y的測試方法,比如:
- test_Demo:
private: y
description: test for 123
inputValue: 123
- test_Demo:
private: n
description: test for 123
inputValue: 123
則test_Demo只會(huì)private被標(biāo)記為y的一次,標(biāo)記為n的則不會(huì)被運(yùn)行
description的數(shù)據(jù)則會(huì)被顯示在報(bào)告中。
在testcase文件夾下面有個(gè)GlobalData.yaml,也是存放測試數(shù)據(jù)的,里面的數(shù)據(jù)會(huì)被用到所有的project中,里面的數(shù)據(jù)如果與project中TestData.yaml的測試數(shù)據(jù)一樣時(shí),則會(huì)被project中TestData.yaml的測試數(shù)據(jù)覆蓋。比如在一個(gè)系統(tǒng)中,可能都會(huì)有用戶名與密碼,則放在GlobalData.yaml中即可,存放數(shù)據(jù)的格式為:
loginname: test1
password: test
總結(jié):如果GlobalData.yaml存在loginname: test1,在ExpectedData.yaml的common結(jié)點(diǎn)下存在loginname: test2,在test_Demo下存在loginname: test3,則在腳本中調(diào)用loginname時(shí),值為test3.
測試數(shù)據(jù)在test_Demo中的調(diào)用方式為:TestData("loginname")