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
基于数据的功能测试经常要求我们进行数据排序的检验,以下代码是我日常工作中常用的,希望对大家有帮助。
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
相关文章推荐
- How to check whether XPCOM has been registered successfully
- 判断是否为完全二叉树 Check whether a binary tree is a complete tree or not
- js小技巧-判断表格是否被选中
- 单链表的实现(包括就地逆转单链表,表排序, 合并单链表、判断表是否有环)
- 找工作笔试-广联达-判断是否为后续排序
- 单链表的实现(包括就地逆转单链表,表排序, 合并单链表、判断表是否有环)
- (PHP实现剑指offer)在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数。
- 判断表格某一列是否重复或空
- PHP 判断字符串是否符合指定格式编码-mb_check_encoding
- Centos7程序里面判断系统是否正在关机或者重启(Check if Centos7 is rebooting or shuting down in program.)
- Selenium2学习-029-WebUI自动化实战实例-027-判断元素是否存在
- Determining whether or not a polygon (2D) has its vertices ordered clockwise or counterclockwise
- (lodash_gcy)hasAttr——判断数组中是否存在某个元素
- 判断排序是否到临界值
- 大表格,多Form元素的提交 判断表单数据是否有被修改过
- JQuery 判断某个属性是否存在 hasAttr
- HasValue 判断可空类型是否有值
- hdu 3342(利用拓扑排序过程判断有向图是否有回路及自环)
- jquery check the object exist(JQuery 判断对象是否存在)
- 判断表格中行的值是否一致