使用seleium测试EXT类库的方法

在seleium-IDE上,打开options,其中core 和IDE两个文本框中,分别导入两个js文件,重启remote后台即可。

 

简单说就是在录制时不会再出现EXT的随机码,就能回放成功了。

 

第一个文件:user-extensions.js

 

 

Selenium.prototype.assertExtEqual = function(expression, text) { var result = this.exteval_r(expression) if (result != text) { Assert.fail("the value of [" + result + "] " + expression + " is not equal with " + text); } }; Selenium.prototype.assertExtGreaterThan = function(expression, text) { var result = this.exteval_r(expression) if (result <= text) { Assert.fail("the value of [" + result + "] " + expression + " is not greater than " + text); } } Selenium.prototype.assertExtGreaterEqualThan = function(expression, text) { var result = this.exteval_r(expression) if (result < text) { Assert.fail("the value of [" + result + "] " + expression + " is not greater equal than " + text); } } Selenium.prototype.assertExtLessThan = function(expression, text) { var result = this.exteval_r(expression) if (result >= text) { Assert.fail("the value of [" + result + "] " + expression + " is not less than " + text); } } Selenium.prototype.assertExtLessEqualThan = function(expression, text) { var result = this.exteval_r(expression) if (result > text) { Assert.fail("the value of [" + result + "] " + expression + " is not less equal than " + text); } } Selenium.prototype.doExecuteExtFunction = function(expression, text) { if (expression.lastIndexOf(")") == expression.length - 1) { this.exteval_r(expression); } else { var scopeObj = this.exteval_r(expression.substring(0, expression .lastIndexOf("."))); var func = this.exteval_r(expression); if (typeof(func) != "function") { Assert.fail("the value of [" + func + "] " + expression + " is not a function"); } var params = []; if (text) { params = text.split(","); } try { func.apply(scopeObj, params); } catch (e) { Assert.fail("error execute function [" + func + "] " + expression); } } } Selenium.prototype.assertExtTrue = function(expression) { var result = this.exteval_r(expression); if (result !== true) { Assert.fail("the value of [" + result + "] " + expression + " is not true"); } } Selenium.prototype.assertExtFalse = function(expression) { var result = this.exteval_r(expression); if (result !== true) { Assert.fail("the value of [" + result + "] " + expression + " is not false"); } } Selenium.prototype.assertExtNull = function(expression, text) { var result = this.exteval_r(expression); if (result !== null) { Assert.fail("the value of [" + result + "] " + expression + " is not null"); } } Selenium.prototype.assertExtNotNull = function(expression, text) { var result = this.exteval_r(expression); if (result === null) { Assert.fail("the value of [" + result + "] " + expression + " is null"); } } Selenium.prototype.assertExtUndefined = function(expression, text) { var result = this.exteval_r(expression); if (result !== undefined) { Assert.fail("the value of [" + result + "] " + expression + " is not undefined"); } } Selenium.prototype.assertExtNotUndefined = function(expression, text) { var result = this.exteval_r(expression); if (result === undefined) { Assert.fail("the value of [" + result + "] " + expression + " is undefined"); } } Selenium.prototype.assertExtPresent = function(expression, text) { var result = this.exteval_r(expression); if (result == null || result == undefined) { Assert.fail("the value of [" + result + "] " + expression + " is not present"); } } Selenium.prototype.assertExtNotPresent = function(expression, text) { var result = this.exteval_r(expression); if (result != null || result != undefined) { Assert.fail("the value of [" + result + "] " + expression + " is present"); } } Selenium.prototype.assertExtMatches = function(expression, text) { var result = this.exteval_r(expression); var reg = new RegExp(text); if (!reg.test(result)) { Assert.fail("the value of [" + result + "] " + expression + " is not match " + text); } } Selenium.prototype.assertExtContains = function(expression, text) { var result = this.exteval_r(expression); if (typeof(result) == "undefined" || result == null) { Assert.fail("the value of " + expression + " dos not contains " + text); } else if (result.indexOf) { if (result.indexOf(text) < 0) { Assert.fail("the value of [" + result + "] " + expression + " dos not contains " + text); } } else { Assert.fail("the value of [" + result + "] " + expression + " is not a String or Array"); } } Selenium.prototype.assertExtTypeof = function(expression, text) { var type = typeof(this.exteval_r(expression)); if (type != text) { Assert.fail("the type of [" + type + "] " + expression + " is not " + text); } } PageBot.prototype.getWrappedWindow = function(extpath) { var win = this.getCurrentWindow() || {}; return win.wrappedJSObject; } Selenium.prototype.getWrappedWindow = function(extpath) { return this.browserbot.getWrappedWindow(); } Selenium.prototype.extEval = function(expression) { var script = expression; if (expression) { var expArr = expression.split("."); expArr[0] = "(window.Ext.getCmp('" + expArr[0] + "')||window.Ext.get('" + expArr[0] + "')||window.Ext.StoreMgr.lookup('" + expArr[0] + "'))"; expression = expArr.join("."); } try { return this.doeval_r(expression); } catch (e) { throw new SeleniumError("the expression " + script + " is not a Ext expression !"); } }; // I have to rewrite the eval function to get the context of window Selenium.prototype.doEval = function(expression) { try { var win = this.getWrappedWindow(); var result = eval_r(expression, win); return result; } catch (e) { throw new SeleniumError("the expression " + expression + " is not a Ext expression !"); } }

 

第二个文件:extension-ide.js

 

var EXT_PREFIX = "ext-gen"; function findExtLocator(e) { function getElementIndex(el, p) { var childs = p.childNodes; for (var i = 0; i < childs.length; i++) { var curr = childs[i]; if (curr == el) { return "[" + (i + 1) + "]"; } } } if (e.id) { var elId = e.id; if (elId.indexOf(EXT_PREFIX) == 0) { var currNode = e; var locator = ""; while (currNode && currNode.tagName.toLowerCase() != "body") { parentNode = currNode.parentNode; locator = this.relativeXPathFromParent(currNode) + locator;// if (parentNode.id && parentNode.id.length > 0 && parentNode.id.indexOf(EXT_PREFIX) != 0) { locator = "//" + parentNode.tagName + "[@id='" + parentNode.id + "']" + locator; return locator; } currNode = currNode.parentNode; } } } return null; } LocatorBuilders.add('ext', findExtLocator); // You can change the priority of builders by setting LocatorBuilders.order. LocatorBuilders.order = ['ext', 'id', 'link', 'name', 'dom:name', 'xpath:link', 'xpath:img', 'xpath:attributes', 'xpath:href', 'dom:index', 'xpath:position'];
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

你说我听海绵宝宝派大星

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值