目前,Tellurium還是建立在Selenium框架之上, 在不久的將來希望Tellurium會開發自己的測試驅動Engine來更好,更有效地支持Tellurium.
盡管Tellurium脫胎于Selenium, 但兩者在概念上是大大的不同。 打個比方,Selenium是C, 而Tellurium是C++。
首先, Selenium主要用于記錄和重播模式(Record and replay), 這是很方便,但是在比較復雜的應用中這種模式并不能很好地工作, 因為你必須記錄可能的所以的測試情況, 除此之外, Data dependency(數據的依賴性)也是個大問題。
第二, Selenium將測試的頁面表述(Locator)和測試代碼混在一起, 很難維護和重復使用(reuse)。
第三, Selenium面對的是一個個單獨的網頁元素, 而且網頁元素的Locator很難作到魯棒性(robust)。
那么Tellurium是如何克服上面的問題的呢?
第一, Tellurium不是記錄和重播模式, 而是注重網頁模塊的。 首先你必須定義網頁模塊和對模塊的方法。 以Google頁面為例, Google搜索模塊可以定義為:
ui.Container(uid: "Google", clocator: [tag: "td"], group: "true"){
InputBox(uid: "SearchBox", clocator: [title: "Google Search"])
SubmitButton(uid: "Search", clocator: [name: "btnG", value: "Google Search"])
SubmitButton(uid: "Feelinglucky", clocator: [value: "I'm Feeling Lucky"])
}
然后, 你可以定義一些對它的操作方法,
def doGoogleSearch(String input){
type "Google.SearchBox", input
pause 500
click "Google.Search"
waitForPageToLoad 30000
}
def doImFeelingLucky(String input){
type "Google.SearchBox", input
pause 500
click "Google.FeelingLucky"
waitForPageToLoad 30000
}
在此之上你可以像寫JUnit測試一樣的寫測試代碼, 例如:
public class GoogleStartPageJavaTestCase extends TelluriumJavaTestCase {
protected static NewGoogleStartPage ngsp;
@BeforeClass
public static void initUi() {
ngsp = new NewGoogleStartPage();
ngsp.defineUi();
}
@Test
public void testGoogleSearch(){
connectUrl("http://www.google.com");
ngsp.doGoogleSearch("tellurium selenium Groovy Test");
}
@Test
public void testGoogleSearchFeelingLucky(){
connectUrl("http://www.google.com");
ngsp.doImFeelingLucky("tellurium selenium DSL Testing");
}
}
其次, 因為Tellurium是面向網頁模塊的, 而不是單獨的元素, 所以它可以應用團體信息來給元素定位(Group Locating)。 比如, 在上面例子中, 元素"Google"可以用它包含的InputBox和SubmitButton中的信息來給
它自己定位。這樣使得這個網頁模塊只利用本身的信息, 而不依賴外部的信息。
另一個Tellurium顯著的特點是它用Composite Locator,就是上面定義的clocator。 clocator很貼近網頁語言
的定義, 而且它的Runtime(運行時)的locator是由Tellurium動態產生的, 比如,你改變了InputBox的title 屬性, 你不需要再修改其他的地方。 這一點和上面的Group Locating使得Tellurium具有很好的魯棒性, 可以自
動適應網頁模塊外和模塊內的變化。
Tellrium核心是用Groovy語言寫的, 這樣你可一用DSL來寫測試代碼。 Tellurium的特點包括:
1)支持JUnit和TestNG
2)測試代碼可以用Java, Groovy或DSL來寫
3)支持Data Driven Testing (數據驅動測試)
4)支持Ant和Maven
Tellurium由下面的子項目構成:
1)Tellurium Core: 核心
2)Tellurium Reference Projects: 有TestNG和JUnit項目教用戶如何用Tellurium
3)Tellurium UI Module Firefox Plugin (TrUMP), 它是一個Firefox的擴展,用戶可以用它來自動生成網頁模塊。
4)Tellurium Widget Extension: 有Dojo和ExtJS的Widget模塊代碼, 這樣你只要在你的項目中加入一些jar文件,你就可以之間定義和測試這些Widget了。
5)Tellurium Engine: 將來的測試驅動模塊。
文章來源于領測軟件測試網 http://www.kjueaiud.com/