在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; 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'];
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) | Powered by Discuz! X3.2 |