GoogleSearchModule.groovy是用戶界面模塊的谷歌搜索,它自化生成Tellurium 所需要的火狐瀏覽器插件TrUMP. doGoogleSearch() 和 doImFeelingLucky() 兩個方法是增加定期谷歌搜索和谷歌“手氣不錯”搜索。
public class GoogleSearchModule extends DslContext {
public void defineUi() {
ui.Container(uid: "Google", clocator: [tag: "table"]) {
InputBox(uid: "Input", clocator: [tag: "input", title: "Google Search", name: "q"])
SubmitButton(uid: "Search", clocator: [tag: "input", type: "submit", value: "Google Search", name: "btnG"])
SubmitButton(uid: "ImFeelingLucky", clocator: [tag: "input", type: "submit", value: "I'm Feeling Lucky", name: "btnI"])
}
}
public void doGoogleSearch(String input) {
keyType "Google.Input", input
pause 500
click "Google.Search"
waitForPageToLoad 30000
}
public void doImFeelingLucky(String input) {
type "Google.Input", input
pause 500
click "Google.ImFeelingLucky"
waitForPageToLoad 30000
}
}
因為Tellurium只支持groovy語言,所以無groovy語言無法直接在Eclipse IDE中運行,需要Eclipse安裝對groovy語言支持的插件。
Groovy-Eclipse 2.5.· 插件下載地址:
http://www.oschina.net/news/·9279/groovy-eclipse-25·
當然,你也可以使用IntelliJ IDEA 工具,它同樣也運行java語言非常的IDE。 而且IntelliJ IDEA本身是支持groovy語言。
Tellurium IDE 插件
這個同樣也是基于firefox瀏覽器的插件有,功能與selenium IDE類似,如果你熟悉selenium IDE的話,Tellurium IDE很容易操作。
Tellurium IDE 插件安裝地址:
https://addons.mozilla.org/en-US/firefox/addon/tellurium-ide/?src=search
注意:本插件不支持新的firefox 9 ,firefox這小子一年換版本比翻書還快,本人使用的是firefox 3.6 版本,用firefox打開上面的鏈接后點擊“add to firefox”根據(jù)提示,瀏覽器開始下載安裝重啟。
在菜單欄---工具----Tellurium IDE打開插件。
我們打開人人網(wǎng)的注冊頁面,填寫個人信息,Tellurium IDE會自動記錄我的操作。
Record :錄制按鈕。打開時默認是按下的,再次點擊將取消錄制狀態(tài)。
Step :單步運行。點擊一次,運行一步。
Run : 運行按鈕。點擊之后將會把腳本從頭到尾運行一遍。
Clear : 清楚腳本。清楚錄制的腳本。
本例子錄制了一個人人網(wǎng)的注冊頁面(不完整,只是填寫了注冊信息,并被“提交”注冊)。
我們切換到Source View標簽,可查看錄制的代碼。
點擊菜單欄File 可選擇將代碼以不同的形式導出或保存到剪切版上。
在Eclipse中運行測試代碼
我們在Eclipse中創(chuàng)建一個NewUiModule.groovy 的文件。并把我Tellurium IDE中錄制的代碼插入,內(nèi)容如下:
class NewUiModule extends DslContext {
public void defineUi() {
ui.Form(uid: "Regform", clocator: [tag: "form", action: "/s-c-i-reg.do", name: "regform", id: "regform", method: "post"]){
InputBox(uid: "RegEmail", clocator: [tag: "input", type: "text", class: "inputtext", id: "regEmail", name: "regEmail"])
InputBox(uid: "Pwd", clocator: [tag: "input", type: "password", class: "inputtext", id: "pwd", name: "pwd"])
InputBox(uid: "Name", clocator: [tag: "input", type: "text", class: "inputtext", id: "name", name: "name"])
RadioButton(uid: "Female", clocator: [tag: "input", type: "radio", value: "女生", id: "female", name: "gender"])
Selector(uid: "Birth_year", clocator: [tag: "select", name: "birth_year"])
Selector(uid: "Birth_month", clocator: [tag: "select", name: "birth_month"])
Selector(uid: "Birth_day", clocator: [tag: "select", name: "birth_day"])
Selector(uid: "Stage", clocator: [tag: "select", name: "stage", id: "stage"])
InputBox(uid: "Icode", clocator: [tag: "input", type: "text", class: "inputtext validate-code", id: "icode", name: "icode"])
Container(uid: "D_email", clocator: [tag: "dl", direct: "true", id: "d_email"]){
UrlLink(uid: "Xid_reg_handle", clocator: [tag: "a", text: "帳號", id: "xid_reg_handle"])
UrlLink(uid: "A", clocator: [tag: "a", text: "手機號"])
}
Container(uid: "Dl_gender", clocator: [tag: "dl", direct: "true", class: "dl_gender"]){
RadioButton(uid: "Male", clocator: [tag: "input", type: "radio", value: "男生", id: "male", name: "gender"])
}
}
connectSeleniumServer()
connectUrl "http://reg.renren.com/xn6245.do?ss=·0··3&rt=27"
type "Regform.RegEmail", "dddd"
type "Regform.RegEmail", "chongshi"
type "Regform.Pwd", "·23456"
type "Regform.Name", "小三"
click "Regform.Female"
selectByLabel "Regform.Birth_year", "80后"
selectByLabel "Regform.Birth_month", "7"
selectByLabel "Regform.Birth_day", "8"
selectByLabel "Regform.Birth_day", "7"
selectByLabel "Regform.Stage", "已經(jīng)工作了"
type "Regform.Icode", "漂亮寶貝"
} //Add your methods here
public void searchDownload(String keyword) {
keyType "TelluriumDownload.Input", keyword
click "TelluriumDownload.Search"
waitForPageToLoad 30000
}
public String[] getAllDownloadTypes() {
return getSelectOptions("TelluriumDownload.DownloadType")
}
public void selectDownloadType(String type) {
selectByLabel "TelluriumDownload.DownloadType", type
}
}