您的位置:软件测试 > 开源软件测试 > 开源功能测试工具 > Selenium
Selenium之常用的方法的封装
作者:网络转载 发布时间:[ 2016/1/12 13:46:17 ] 推荐标签:软件测试工具 功能测试

  一.概述
  selenium在编写页面中函数的时候,需要调用的某些方法是很多PageObject都需要调用到的,而且这些原始的方法需要进行封装
  以便使脚本更好的实现功能,那么有哪些方法是需要经常用到的呢?
  二.selenium封装的常用的方法
1  /**
2      * 判断是否找到对象
3      * @param by
4      * @return
5      */
6     private boolean waitToDisplayed(final By by){
7         boolean waitDisplayed=false;
8         try {
9             waitDisplayed=new WebDriverWait(driver,Config.waitTime).until(new ExpectedCondition<Boolean>(){
10                 @Override
11                 public Boolean apply(WebDriver d) {
12                     // TODO Auto-generated method stub
13                     return d.findElement(by).isDisplayed();
14                 }
15             });
16
17         } catch (Exception e) {
18             // TODO: handle exception
19             throw new DefinedException(by.toString() + " is not exist until " +Config.waitTime+" sec in file: "+yamlFile);
20         }
21         return waitDisplayed;
22     }
1 /**
2      * 判断对象是否没出现
3      * @param key
4      * @param replace
5      * @return
6      */
7     private boolean waitToNonDisplayed(String key,String[] replace){
8         boolean waitNonDisplayed=false;
9         final By by=this.getBy(key, replace);
10         try {
11             waitNonDisplayed=new WebDriverWait(driver,Config.waitTime).until(new ExpectedCondition<Boolean>(){
12                 @Override
13                 public Boolean apply(WebDriver d) {
14                     // TODO Auto-generated method stub
15                     if(d.findElements(by).isEmpty()||!d.findElement(by).isDisplayed()){
16                         return true;
17                     }else{
18                         return false;
19                     }
20                 }
21             });
22         } catch (Exception e) {
23             // TODO: handle exception
24             throw new DefinedException(by.toString() + " is also exist until " +Config.waitTime+" sec in file: "+yamlFile);
25         }
26         return waitNonDisplayed;
27     }

上一页12下一页
软件测试工具 | 联系我们 | 投诉建议 | 诚聘英才 | 申请使用列表 | 网站地图
沪ICP备07036474 2003-2017 版权所有 上海泽众软件科技有限公司 Shanghai ZeZhong Software Co.,Ltd