測試方法
Tellurium采用一種新的方式,通過(guò)UI module的概念來(lái)進(jìn)行自動(dòng)化測試。使用對象封裝Web UI的元素,因此不再需要手動(dòng)生成和重構UI的定位器。UI module是個(gè)簡(jiǎn)單的復合UI對象,由嵌套的基本UI對象組成。
這個(gè)框架可以在兩種模式下運行。第一種模式是作為Selenium框架的wrapper來(lái)工作。也就是說(shuō),Tellurium core基于UI module中的UI對象屬性,生成運行時(shí)定位器。生成的運行時(shí)定位器然后通過(guò)Tellurium擴展傳遞給Selenium core來(lái)調用。
Tellurium還在開(kāi)發(fā)它自己的驅動(dòng)引擎,即Tellurium Engine,以更好更有效地支持UI module。
首先,Tellurium Core把UI module轉換成JSON的表示形式。
然后在使用UI module時(shí),JSON表示的數據被第一次傳遞給Tellurium Engine。
接著(zhù)Tellurium Engine使用Santa算法,定位整個(gè)UI module,并將其存在緩存中。
在接下來(lái)的調用中,會(huì )直接使用緩存的UI module,而不需要重新定位了。
此外,Tellurium Core把多條命令合并成一條批處理命令,叫做宏命令,然后在一次調用中把這條批處理發(fā)送給Tellurium Engine。這樣可以減少請求/響應帶來(lái)的延遲。
下面這個(gè)例子,使用了該項目網(wǎng)站上的問(wèn)題搜索UI,來(lái)表述框架背后的思想。
我們從為問(wèn)題搜索的UI定義UI module開(kāi)始吧:
ui.Form(uid: "issueSearch", clocator: [action: "list", method: "GET"]) {
Selector(uid: "issueType", clocator: [name: "can", id: "can", direct:
"true"])
TextBox(uid: "searchLabel", clocator: [tag: "span", text: "for"])
InputBox(uid: "searchBox", clocator: [type: "text", name: "q", id: "q"])
SubmitButton(uid: "searchButton", clocator: [value: "Search", direct:
"true"])
}
然后使用下面這個(gè)測試方法:
public void searchIssue(String type, String issue){
select "issueSearch.issueType", type
keyType "issueSearch.searchBox", issue
click "issueSearch.searchButton"
waitForPageToLoad 30000
}
如果有一天,你需要把Selector修改成輸入框,那我們只需要更新對應的UI module:
ui.Form(uid: "issueSearch", clocator: [action: "list", method: "GET"]) {
InputBox(uid: "issueType", clocator: [name: "can", direct: "true"])
TextBox(uid: "searchLabel", clocator: [tag: "span", text: "for"])
InputBox(uid: "searchBox", clocator: [type: "text", name: "q", id: "q"])
SubmitButton(uid: "searchButton", clocator: [value: "Search", direct: "true"])
}
然后修改命令:
select "issueSearch.issueType", type
為:
type "issueSearch.issueType", type
其余則保持不變。
如果有動(dòng)態(tài)的Web內容,比如Google Books的網(wǎng)站,它包含了一個(gè)圖書(shū)分類(lèi)的列表,每個(gè)分類(lèi)中包含一個(gè)圖書(shū)列表。針對這樣UI的UI module會(huì )出奇的簡(jiǎn)單:
ui.Container(uid: "GoogleBooksList", clocator: [tag: "table", id: "hp_table"]) {
List(uid: "subcategory", clocator: [tag: "td", class: "sidebar"], separator:
"div") {
Container(uid: "{all}") {
TextBox(uid: "title", clocator: [tag: "div", class: "sub_cat_title"])
List(uid: "links", separator: "p") {
UrlLink(uid: "{all}", clocator: [:])
}
}
}}
Tellurium UID描述語(yǔ)言為定義動(dòng)態(tài)Web內容提供了更多的靈活性。我們來(lái)看個(gè)復雜點(diǎn)的例子。
文章來(lái)源于領(lǐng)測軟件測試網(wǎng) http://kjueaiud.com/