Selenium IDE 扩展函数,判断表格某列是否被排序.(Check whether a column has been ordered.)...

a data based functional testing often needs to check the data orderation, I use the function listed below in my daily work, I hope it can help you rise up your efficiency.
基于数据的功能测试经常要求我们进行数据排序的检验,以下代码是我日常工作中常用的,希望对大家有帮助。

Selenium.prototype.isColumnOrdered = function(locator,order){
    var locators = locator.split("|");
    var tableLocator = locators[0];
    var headNum = parseInt(locators[1]);
    var bottomNum = parseInt(locators[2]);
    var identifier = locators[3];
    var colNum = null;
    var elem = null;
    
    if(identifier.indexOf(":") >= 0){
        colNum = parseInt(identifier.substring(0,identifier.indexOf(":")));
        elem = identifier.substr(identifier.indexOf(":")+1);
    }else{
        colNum = parseInt(identifier);
    }
    
    var table = this.page().findElement(tableLocator);
    
    if(table != null){
        for(i=headNum; i<table.rows.length-bottomNum; i++){
            if((i+1)<table.rows.length-bottomNum){
                var fir = "";
                var sec = "";
                
                if(elem != null){
                    var path1 = tableLocator+"//tr["+ (i+1) +"]/td["+ (colNum+1) +"]//"+elem;
                    var path2 = tableLocator+"//tr["+ (i+2) +"]/td["+ (colNum+1) +"]//"+elem;
                    fir = this.getText(path1);
                    sec = this.getText(path2);
                    //alert(fir+""n"+sec);
                }else{
                    fir = getText(table.rows[i].cells[colNum]).trim();
                    sec = getText(table.rows[i+1].cells[colNum]).trim();
                }
                
                if(order.toUpperCase() == "A"){
                    if(fir > sec){
                        //alert(fir+""n"+sec);
                        return false;
                    }
                }else if(order.toUpperCase() == "D"){
                    if( fir < sec){
                        //alert(fir+""n"+sec);
                        return false;
                    }
                }
            }
        }
        
        return true;
    }else{
        throw new SeleniumError("can't find the element"""+tableLocator+"""");
    }
}


how to use:
call function: verifyColumnOrdered
param1 format: tablelocator|rowCountBeforeDataArea|rowCountAfterDataArea
    example: //table[2] | 2 |3
                  //table[2] - xPath of a table;
                  2 - there 2 rows before data area in this table;
                  3 - there are 3 rows after data area in this table
param2: order
            A: ascending
            D: descending

转载于:https://www.cnblogs.com/nuelaleo/archive/2008/04/10/1147533.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值