您的位置:首页 > 其它

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

2008-04-10 22:41 405 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐