Locator
Locator是用来定位一个元素在网页DOM中的位置,Tellurium支持两种Locator, 一种叫 Base Locator , 用“locator”标识,它是一个相对的XPath. 如:
InputBox(uid: "SearchBox", locator: "//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);
}
...
}
延伸阅读
文章来源于领测软件测试网 https://www.ltesting.net/