- 浏览: 463863 次
- 性别:
- 来自: 深圳
-
文章分类
- 全部博客 (354)
- 面向对象分析设计/系统架构 (12)
- Mysql/Orcal11g (13)
- JSP/Java//Python/Xharbour (66)
- 软件测试 (21)
- 信息安全小知识 (1)
- Android (5)
- IT生活/哲学/兵法 (23)
- 软件工程/UML/需求分析学习与实践 (6)
- 操作系统/网络/组成原理 (9)
- 持续集成Maven/Hudson/自动化测试 (9)
- eBay /Paypal developer (10)
- Hadoop/HBase/Solr (0)
- 重构分析及其思考 (2)
- 企业架构 (7)
- 分析模式/设计模式 (4)
- SSH学习笔记 (1)
- Quartz及其JWatch监控 (0)
- Linux服务器 (0)
- ExtJs学习笔记 (1)
- 重读java编程思想 (3)
- ESB/SOA/WebServices (0)
- SpringMVC/Struts/Hibernate/Spring (7)
- Xharbour/Pelles C/ SQLite3 (0)
- Magento 电商 (1)
- Object C (1)
- note/redis (0)
- SpringBoot (0)
最新评论
-
snow8261:
太粗略了。
企业架构之数据架构 -
haithink:
面试成功没?
JVM 加载Class文件的原理及其机制 -
feisi0003731843:
不好意思我没有重启,重启后好多了,可有的地方回放还是不成功的。 ...
Selenium IDE测试ExtJs一种测试解决办法 -
feisi0003731843:
这个好像不行吧,我试过了不好使啊。还是用id来做的。不能用啊。 ...
Selenium IDE测试ExtJs一种测试解决办法 -
yuchensuifeng:
您好,静态页面是可以的,但是,我指定error-page为js ...
JSP创建错误处理页面
最近发现要使用ExtJs测试其实很麻烦,因为ExtJs的id是变化的,而Selenium IDE录制完后,ExtJs的下次打开页面,就无法进行回放了。因此很麻烦,不过通过一些网友进行交流得到如下一些测试方法:
1. 使用Xpath进行定位
2. 适当使用selenium..runScript()方法
3.应用Selenium IDE的extensions
下面我只针对第3种方法进行总结。
如果你想知道第三种方法的原理:请你在你的firefox浏览器上
输入
chrome://selenium-ide/content/recorder-handlers.js
chrome://selenium-ide/content/locatorBuilders.js
通过上面两个js你大致可以了解Selenium IDE录制的原理。
要用Selen现在我ium IDE的extensions。
步骤:在Selenium IDE的Options进入,在点击Options显示如下一个节目
在该页面你要注意:
Selenium Core extensions(user-extensions.js)
Selenium IDE extensions
下面我们准备两个脚本来进行extesions。
该代码命名为user-extensions.js通过Selenium Core extensions(user-extensions.js)后的Browser选择中自己写的user-extensions.js.或者也可以不要改js但是下面这个js是一定要的(放入Selenium IDE extensions)。
该段代码是必须的。产生的效果是让Selenium IDE在录制Extjs的时候能够回放成功。
总结下使用步骤:
第一:将第一段js代码放入Selenium Core extensions(user-extensions.js)
第二:将第二段js代码放入Selenium IDE extensions 这是必须的。
现在你可以使用Selenium IDE来测试ExtJs了。你可以看看是不是可以正常进行录制和回放。ExtJs没有ZK厚道,ZK官网提供了一个接口来实现Selenium IDE的测试。
引用
1. 使用Xpath进行定位
2. 适当使用selenium..runScript()方法
3.应用Selenium IDE的extensions
下面我只针对第3种方法进行总结。
如果你想知道第三种方法的原理:请你在你的firefox浏览器上
输入
引用
chrome://selenium-ide/content/recorder-handlers.js
chrome://selenium-ide/content/locatorBuilders.js
通过上面两个js你大致可以了解Selenium IDE录制的原理。
要用Selen现在我ium IDE的extensions。
步骤:在Selenium IDE的Options进入,在点击Options显示如下一个节目

在该页面你要注意:
Selenium Core extensions(user-extensions.js)
Selenium IDE extensions
下面我们准备两个脚本来进行extesions。
Selenium.prototype.assertExtEqual = function(expression, text) { /** * the euqal assertion of ext * @param expression ext expression , just like "button1.text" or "text1.getValue()" * @param String target value */ var result = this.extEval(expression) if (result != text) { Assert.fail("the value of [" + result + "] " + expression + " is not equal with " + text); } }; Selenium.prototype.assertExtGreaterThan = function(expression, text) { /** * the greater than assertion of ext * @param expression ext expression , just like "button1.text" or "text1.getValue()" * @param String target value */ var result = this.extEval(expression) if (result <= text) { Assert.fail("the value of [" + result + "] " + expression + " is not greater than " + text); } } Selenium.prototype.assertExtGreaterEqualThan = function(expression, text) { /** * the greater and equal than assertion of ext * @param expression ext expression , just like "button1.text" or "text1.getValue()" * @param String target value */ var result = this.extEval(expression) if (result < text) { Assert.fail("the value of [" + result + "] " + expression + " is not greater equal than " + text); } } Selenium.prototype.assertExtLessThan = function(expression, text) { /** * the less than assertion of ext * @param expression ext expression , just like "button1.text" or "text1.getValue()" * @param String target value */ var result = this.extEval(expression) if (result >= text) { Assert.fail("the value of [" + result + "] " + expression + " is not less than " + text); } } Selenium.prototype.assertExtLessEqualThan = function(expression, text) { /** * the less and equal than assertion of ext * @param expression ext expression , just like "button1.text" or "text1.getValue()" * @param String target value */ var result = this.extEval(expression) if (result > text) { Assert.fail("the value of [" + result + "] " + expression + " is not less equal than " + text); } } Selenium.prototype.doExecuteExtFunction = function(expression, text) { /** * do ext function ,if the expression end with ")" ,the params is not useful * @param expression ext expression return a ext function, just like "button1.getText" or "text1.getValue()" * @param String params ,just like "a,b,c" */ if (expression.lastIndexOf(")") == expression.length - 1) { this.extEval(expression); } else { var scopeObj = this.extEval(expression.substring(0, expression .lastIndexOf("."))); var func = this.extEval(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) { /** * the true assertion of ext * @param expression ext expression , just like "button1.hidden" */ var result = this.extEval(expression); if (result !== true) { Assert.fail("the value of [" + result + "] " + expression + " is not true"); } } Selenium.prototype.assertExtFalse = function(expression) { /** * the false assertion of ext * @param expression ext expression , just like "button1.hidden" */ var result = this.extEval(expression); if (result !== true) { Assert.fail("the value of [" + result + "] " + expression + " is not false"); } } Selenium.prototype.assertExtNull = function(expression, text) { /** * the null assertion of ext * @param expression ext expression , just like "button1.text" */ var result = this.extEval(expression); if (result !== null) { Assert.fail("the value of [" + result + "] " + expression + " is not null"); } } Selenium.prototype.assertExtNotNull = function(expression, text) { /** * the not null assertion of ext * @param expression ext expression , just like "button1.text" */ var result = this.extEval(expression); if (result === null) { Assert.fail("the value of [" + result + "] " + expression + " is null"); } } Selenium.prototype.assertExtUndefined = function(expression, text) { /** * the undefined assertion of ext * @param expression ext expression , just like "button1" */ var result = this.extEval(expression); if (result !== undefined) { Assert.fail("the value of [" + result + "] " + expression + " is not undefined"); } } Selenium.prototype.assertExtNotUndefined = function(expression, text) { /** * the not undefined assertion of ext * @param expression ext expression , just like "button1" */ var result = this.extEval(expression); if (result === undefined) { Assert.fail("the value of [" + result + "] " + expression + " is undefined"); } } Selenium.prototype.assertExtPresent = function(expression, text) { /** * the present assertion of ext * @param expression ext expression , just like "button1" */ var result = this.extEval(expression); if (result == null || result == undefined) { Assert.fail("the value of [" + result + "] " + expression + " is not present"); } } Selenium.prototype.assertExtNotPresent = function(expression, text) { /** * the not present assertion of ext * @param expression ext expression , just like "button1" */ var result = this.extEval(expression); if (result != null || result != undefined) { Assert.fail("the value of [" + result + "] " + expression + " is present"); } } Selenium.prototype.assertExtMatches = function(expression, text) { /** * the matches assertion of ext * @param expression ext expression , just like "button1.text" or "text1.getValue()" * @param String target value */ var result = this.extEval(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) { /** * the contains assertion of ext * @param expression ext expression , just like "button1.text" or "text1.getValue()" * @param String target value */ var result = this.extEval(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) { /** * the typeof assertion of ext * @param expression ext expression , just like "button1.text" or "text1.getValue()" * @param String target value */ var type = typeof(this.extEval(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(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) { /** * execute js ecpression * * @param {Object} * expression js expression */ try { var win = this.getWrappedWindow(); var result = eval(expression, win); return result; } catch (e) { throw new SeleniumError("the expression " + expression + " is not a Ext expression !"); } }
该代码命名为user-extensions.js通过Selenium Core extensions(user-extensions.js)后的Browser选择中自己写的user-extensions.js.或者也可以不要改js但是下面这个js是一定要的(放入Selenium IDE extensions)。
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'];
该段代码是必须的。产生的效果是让Selenium IDE在录制Extjs的时候能够回放成功。
总结下使用步骤:
引用
第一:将第一段js代码放入Selenium Core extensions(user-extensions.js)
第二:将第二段js代码放入Selenium IDE extensions 这是必须的。
现在你可以使用Selenium IDE来测试ExtJs了。你可以看看是不是可以正常进行录制和回放。ExtJs没有ZK厚道,ZK官网提供了一个接口来实现Selenium IDE的测试。
评论
2 楼
feisi0003731843
2012-08-30
不好意思我没有重启,重启后好多了,可有的地方回放还是不成功的。
1 楼
feisi0003731843
2012-08-30
这个好像不行吧,我试过了不好使啊。还是用id来做的。不能用啊。
发表评论
-
再谈Selenium测试之精要
2011-09-01 09:39 2036最近在使用Selenium做ExtJs的测试的时候,有一些 ... -
CI之(Hudson、Maven、SVN)详解一
2010-12-10 16:38 3838之前有发过两篇关于H ... -
炒持续集成续集
2010-07-24 20:17 1459通过对炒持续集成这 ... -
炒持续集成这道菜
2010-07-16 10:45 1740关于持续集成,越来越适应小团队的开发测试发布了。09年那会 ... -
第三幅Selenium IDE和各种计算机语言
2010-07-03 21:19 1390根据 下面看看Selenium IDE支持的一些计算机语言。 ... -
Selenium第一部曲之Selenium IDE窗口介绍
2010-06-21 20:53 1097这篇主要介绍下Seleniu ... -
Selenium第一部曲之Selenium IDE插件的安装和注意事项
2010-06-19 17:21 3546这篇主要针对Selenium 第 ... -
Selenium第一部曲
2010-06-19 16:53 942本该进行总结的知识,直到现在才进行第一部曲的总结。接触Sele ...
相关推荐
这里提到的一种方法是利用Selenium IDE的扩展(Extensions)功能。这种方法涉及到对Selenium IDE进行自定义,以适应ExtJs特有的行为。 首先,我们来看一下如何使用Xpath进行定位。由于ExtJs组件通常具有独特的结构...
这种方式绕过了Selenium IDE对静态元素ID的依赖,提供了一种灵活的测试手段。 3. **应用Selenium IDE的extensions**:Selenium IDE支持自定义扩展,即可以在其基础上添加额外的功能或修改原有行为。通过编辑`user-...
1. **Java编程**:Java是一种跨平台、面向对象的编程语言,被广泛应用于服务器端开发。在这个项目中,Java作为后端编程语言,负责处理业务逻辑、数据操作以及与前端交互。可能涉及到的技术包括Spring框架、Hibernate...