Locator
Locator是用來定位一個元素在網頁DOM中的位置,Tellurium支持兩種Locator, 一種叫 Base Locator , 用“locator”標識,它是一個相對的XPath. 如:
InputBox(uid: "SearchBox", locator: "http://input[@title='Google Search']")
另一個是 Composite Locator , 用“clocator”來標識,它是由一組屬性構成,如
InputBox(uid: "SearchBox", clocator: [title: "Google Search"])
Composite Locator 是Tellurium的缺省Locator, 它容易寫,表敘性好,方便動態生成Runtime Locator.
UI模塊
UI模塊是一個復合的Tellurium物件,它是由一些單個Tellurium物件嵌套構成。一個UI模塊往往代表DOM的一個子樹。比如Google首頁搜索模塊就可以表敘為
ui.Container(uid: "GoogleSearchModule", clocator: [tag: "td"], group: "true"){
InputBox(uid: "Input", clocator: [title: "Google Search"],respond: ["focus", "mouseOver"])
SubmitButton(uid: "Search", clocator: [name: "btnG", value: "Google Search"])
SubmitButton(uid: "ImFeelingLucky", clocator: [value: "I'm Feeling Lucky"])
}
UI模塊的最外層元素以定要以"ui."開始。這里group為“true”表示Tellurium用利用UI元素之間的關系來協助它們在網頁DOM中的定位。respond屬性定義了InputBox需要觸發“focus”和“mouseOver”事件,Tellurium會自動觸發這些事件的。
測試案例>Tellurium測試案例
Tellurium測試代碼可以用Java, Groovy, 或純DSL腳本來寫。無論哪種方法,Tellurium要求你定義獨立的UI模塊,使之和測試代碼分離,以便于維護。UI模塊必須繼承Tellurium的DslContext class, 一般你還需定義對UI模塊的操作方法。例如:
class GoogleSearchModule extends DslContext{
public void defineUi() {
ui.Container(uid: "google_start_page", clocator: [tag: "td"], group: "true"){
InputBox(uid: "searchbox", clocator: [title: "Google Search"])
SubmitButton(uid: "googlesearch", clocator: [name: "btnG", value: "Google Search"])
SubmitButton(uid: "Imfeelinglucky", clocator: [value: "I'm Feeling Lucky"])
}
}
def doGoogleSearch(String input){
keyType "searchbox", input
pause 500
click "googlesearch"
waitForPageToLoad 30000
}
def doImFeelingLucky(String input){
type "searchbox", input
pause 500
click "Imfeelinglucky"
waitForPageToLoad 30000
}
}
如果你的測試案例用JUnit來寫,你需要繼承TelluriumJavaTestCase.
public class GoogleSearchTestCase extends TelluriumJavaTestCase {
private static GoogleSearchModule gsm;
@BeforeClass
public static void initUi() {
gsm = new GoogleSearchModule();
gsm.defineUi();
}
@Before
public void connectToGoogle() {
connectUrl("http://www.google.com");
}
@Test
public void testGoogleSearch() {
gsm.doGoogleSearch("tellurium . ( Groovy ) Test");
}
@Test
public void testGoogleSearchFeelingLucky() {
gsm.doImFeelingLucky("tellurium automated Testing");
}
}
TestNG的案例類似,除了你要繼承TelluriumTestNGTestCase。如果用Groovy, 你需要繼承TelluriumGroovyTestCase.
Tellurium配置
Tellurium用一個配置文件TelluriumConfig.groovy來配置系統。它包括對Selenium服務器和Tellurium框架本身的配置,如:
tellurium{
//embedded selenium server configuration
embeddedserver {
//port number
port = "4445"
//whether to use multiple windows
useMultiWindows = false
runInternally = true
profile = ""
}
//event handler
eventhandler{
//whether we should check if the UI element is presented
checkElement = true
//wether we add additional events like "mouse over"
extraEvent = true
}
//data accessor
accessor{
//whether we should check if the UI element is presented
checkElement = false
}
connector{
//selenium server host
//please change the host if you run the Selenium server remotely
serverHost = "localhost"
//server port number the client needs to connect
port = "4445"
//base URL
baseUrl = "http://localhost:8080"
//Browser setting, valid options are
// *firefox [absolute path]
// *iexplore [absolute path]
// *chrome
// *iehta
browser = "*chrome"
}
datadriven{
dataprovider{
reader = "PipeFileReader"
}
}
test{
result{
reporter = "XMLResultReporter"
output = "Console"
filename = "TestResult.output"
}
exception{
captureScreenshot = true
filenamePattern = "Screenshot?.png"
}
}
uiobject{
builder{
//example:
SelectMenu="org.tellurium.builder.SelectMenuBuilder"
}
}
widget{
module{
//define your widget modules here, for example Dojo or ExtJs
included=""
}
}
}
此外,Tellurium還提供了方法讓用戶來覆蓋Tellurium中的配置,
public class GoogleSearchModuleTestCase extends TelluriumJavaTestCase
{
static{
setCustomConfig(true, 5555, "*chrome", true, null);
}
...
}
延伸閱讀
文章來源于領測軟件測試網 http://www.kjueaiud.com/