Tellurium中关于Container的优化

[b]一.概述[/b]
在Tellurium中,所有的页面元素和方法都会写在groovy文件中,一个完整的groovy文件可以是这个样子的,以google首页为例:

public class GoogleHomeModule extends DslContext{

public void defineGoogleHomeModule(){
ui.Container(uid: "root", clocator: [tag: "center"]){
InputBox(uid: "input", clocator: [name: "q"])
SubmitButton(uid: "gSearch", clocator: [name: "btnG"])
SubmitButton(uid: "lucky", clocator: [name: "btnI"])
Image(uid: "logo", clocator: [id: "logo"])
}
}
public void doGoogleSearch(String input){
pause TelluriumConstant.PAUSELOW
type "root.input", input
pause TelluriumConstant.PAUSELOW
click "root.gSearch"
waitForPageToLoad TelluriumConstant.WAIT
}
}

其中ui.Container这部分是我们可以做优化的地方

[b]二.优化[/b]
首先,直接用Tellurium IDE产生出我们需要的代码,最初工具产生的代码是这样的:

ui.Container(uid: "Table", clocator: [tag: "table"]){
SubmitButton(uid: "Google", clocator: [tag: "input", type: "submit", class: "lsb", value: "Google 搜索", name: "btnG"])
Container(uid: "Section", clocator: [tag: "tr"]){
Container(uid: "Part", clocator: [tag: "td", direct: "true"]){
InputBox(uid: "Q", clocator: [tag: "input", title: "Google 搜索", class: "lst", name: "q"])
SubmitButton(uid: "Input", clocator: [tag: "input", type: "submit", class: "lsb", value: " 手气不错 ", name: "btnI"])
}
}
}


可以看到以上的Container中,我们所需要的InputBox在最底层,上面有3个父节点.如果要做一个搜索操作的话,写出来的代码会是这样:

type "Table.Selection.Part.Q", "james"
click "Table.Google"

这样的话,一个操作中对页面元素的依赖性很高,不容易维护.由于Tellurium也是(可以)用Xpath去解析一个元素,所以,比较理想的状况是这样去操作元素:

type "Table.Q", "james"
click "Table.Google"

所以,优化过的Container最好是这个样子:

ui.Container(uid: "Table", clocator: [tag: "Table"]){
InputBox(uid: "Q", clocator: [name: "q"])
SubmitButton(uid: "Google", clocator: [name: "btnG"])
SubmitButton(uid: "lucky", clocator: [name: "btnI"])
Image(uid: "logo", clocator: [id: "logo"])
}


在以上代码中,将所有中间的Container,多余的元素属性,通通删除掉.让我们对所需要的元素的寻找,仅仅依赖于该元素的name,以及最上层Container的属性(tag,name).

[b]三.总结[/b]
跟Selenium一样,我们的目标是要将页面元素的依赖性降低,最好的结果是仅仅依赖于元素的ID或者Name
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值