測試方法
Tellurium采用一種新的方式,通過UI module的概念來進行自動化測試。使用對象封裝Web UI的元素,因此不再需要手動生成和重構UI的定位器。UI module是個簡單的復合UI對象,由嵌套的基本UI對象組成。
這個框架可以在兩種模式下運行。第一種模式是作為Selenium框架的wrapper來工作。也就是說,Tellurium core基于UI module中的UI對象屬性,生成運行時定位器。生成的運行時定位器然后通過Tellurium擴展傳遞給Selenium core來調用。
Tellurium還在開發它自己的驅動引擎,即Tellurium Engine,以更好更有效地支持UI module。
首先,Tellurium Core把UI module轉換成JSON的表示形式。
然后在使用UI module時,JSON表示的數據被第一次傳遞給Tellurium Engine。
接著Tellurium Engine使用Santa算法,定位整個UI module,并將其存在緩存中。
在接下來的調用中,會直接使用緩存的UI module,而不需要重新定位了。
此外,Tellurium Core把多條命令合并成一條批處理命令,叫做宏命令,然后在一次調用中把這條批處理發送給Tellurium Engine。這樣可以減少請求/響應帶來的延遲。
下面這個例子,使用了該項目網站上的問題搜索UI,來表述框架背后的思想。
我們從為問題搜索的UI定義UI module開始吧:
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"])
}
然后使用下面這個測試方法:
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
其余則保持不變。
如果有動態的Web內容,比如Google Books的網站,它包含了一個圖書分類的列表,每個分類中包含一個圖書列表。針對這樣UI的UI module會出奇的簡單:
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描述語言為定義動態Web內容提供了更多的靈活性。我們來看個復雜點的例子。
文章來源于領測軟件測試網 http://www.anti-gravitydesign.com/