在浏览器中测试 extjs 代码的任何建议,最好使用 selenium? [英] Any suggestions for testing extjs code in a browser, preferably with selenium?

查看:31
本文介绍了在浏览器中测试 extjs 代码的任何建议,最好使用 selenium?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经成功地使用 selenium 来处理高级网站测试(除了模块级别的大量 python doctests).然而,现在我们在很多页面上使用 extjs,并且证明很难将 Selenium 测试合并到像网格这样的复杂组件中.

We've been using selenium with great success to handle high-level website testing (in addition to extensive python doctests at a module level). However now we're using extjs for a lot of pages and its proving difficult to incorporate Selenium tests for the complex components like grids.

有没有人成功地为基于 extjs 的网页编写自动化测试?许多谷歌搜索发现有类似问题的人,但答案很少.谢谢!

Has anyone had success writing automated tests for extjs-based web pages? Lots of googling finds people with similar problems, but few answers. Thanks!

推荐答案

用 Selenium 测试 ExtJS 的最大障碍是 ExtJS 不呈现标准 HTML 元素,而 Selenium IDE 会天真地(并且正确地)生成针对元素的命令只是作为装饰——帮助 ExtJS 处理整个桌面外观的多余元素.以下是我在针对 ExtJS 应用编写自动 Selenium 测试时收集的一些提示和技巧.

The biggest hurdle in testing ExtJS with Selenium is that ExtJS doesn't render standard HTML elements and the Selenium IDE will naively (and rightfully) generate commands targeted at elements that just act as decor -- superfluous elements that help ExtJS with the whole desktop-look-and-feel. Here are a few tips and tricks that I've gathered while writing automated Selenium test against an ExtJS app.

通过在 Firefox 上使用 Selenium IDE 记录用户操作来生成 Selenium 测试用例时,Selenium 会将记录的操作基于 HTML 元素的 id.但是,对于大多数可点击元素,ExtJS 使用生成的 id,如ext-gen-345",即使没有更改代码,这些 id 在后续访问同一页面时也可能会发生变化.在为测试记录用户操作后,需要手动完成所有依赖于生成的 id 的操作并替换它们.可以进行两种类型的替换:

When generating Selenium test cases by recording user actions with Selenium IDE on Firefox, Selenium will base the recorded actions on the ids of the HTML elements. However, for most clickable elements, ExtJS uses generated ids like "ext-gen-345" which are likely to change on a subsequent visit to the same page, even if no code changes have been made. After recording user actions for a test, there needs to be a manual effort to go through all such actions that depend on generated ids and to replace them. There are two types of replacements that can be made:

CSS 定位器以css="开头,XPath 定位器以//"开头(xpath="前缀是可选的).CSS 定位器不那么冗长,更易于阅读,应该优先于 XPath 定位器.但是,在某些情况下,可能需要使用 XPath 定位器,因为 CSS 定位器根本无法对其进行剪切.

CSS locators begin with "css=" and XPath locators begin with "//" (the "xpath=" prefix is optional). CSS locators are less verbose and are easier to read and should be preferred over XPath locators. However, there can be cases where XPath locators need to be used because a CSS locator simply can't cut it.

由于 ExtJS 执行的复杂渲染,某些元素需要的不仅仅是简单的鼠标/键盘交互.例如,一个 Ext.form.CombBox 并不是一个真正的

发送“验证码”获取 | 15天全站免登陆