简体   繁体   English

使用Selenium-IDE和丰富的Javascript应用程序?

[英]Using Selenium-IDE with a rich Javascript application?

Problem 问题

At my workplace, we're trying to find the best way to create automated-tests for an almost wholly javascript-driven intranet application. 在我的工作场所,我们正在努力寻找为几乎完全由javascript驱动的Intranet应用程序创建自动化测试的最佳方法。 Right now we're stuck trying to find a good tradeoff between: 现在我们一直试图找到一个很好的权衡:

  • Application code in reusable and nest-able GUI components. 应用程序代码在可重用和可嵌套的GUI组件中。
  • Tests which are easily created by the testing team 测试团队可以轻松创建的测试
  • Tests which can be recorded once and then automated 测试可以记录一次然后自动化
  • Tests which do not break after small cosmetic changes to the site 在小型化妆品改变现场后不会破坏的测试

XPath expressions (or other possible expressions, like jQuery selectors) naively generated from Selenium-IDE are often non-repeatable and very fragile. 从Selenium-IDE天真地生成的XPath表达式(或其他可能的表达式,如jQuery选择器)通常是不可重复的并且非常脆弱。 Conversely, having the JS code generate special unique ID values for every important DOM-element on the page... well, that is its own headache, complicated by re-usable GUI components and IDs needing to be consistent when the test is re-run. 相反,让JS代码为页面上的每个重要DOM元素生成特殊的唯一ID值...好吧,这是它自己的头痛,复杂的可重用GUI组件和ID需要在测试重新进行时保持一致跑。

What successes have other people had with this kind of thing? 其他人对这种事情有什么成功? How do you do automated application-level testing of a rich JS interface? 如何对丰富的JS接口进行自动化应用程序级测试?

Limitations 限制

  • We are using JavascriptMVC 2.0, hopefully 3.0 soon so that we can upgrade to jQuery 1.4.x. 我们正在使用JavascriptMVC 2.0,希望很快3.0,以便我们可以升级到jQuery 1.4.x.
  • The test-making folks are mostly trained to use Selenium IDE to directly record things. 测试人员大多受过训练,使用Selenium IDE直接记录事物。
  • The test leads would prefer a page-unique HTML ID on each clickable element on the page... 测试主管更喜欢页面上每个可点击元素的页面唯一HTML ID ...
  • Training the testers to write or alter special expressions (such as telling them which HTML class-names are important branching points) is a no-go. 训练测试人员编写或更改特殊表达式(例如告诉他们哪些HTML类名称是重要的分支点)是不行的。
  • We try to make re-usable javascript components, but this means very few GUI components can treat themselves (or what they contain) as unique. 我们尝试制作可重用的javascript组件,但这意味着很少有GUI组件可以将自己(或它们包含的内容)视为唯一。
  • Some of our components already use HTML ID values in their operation. 我们的一些组件已在其操作中使用HTML ID值。 I'd like to avoid doing this anyway , but it complicates the idea of ID-based testing. 无论如何 ,我想避免这样做,但它使基于ID的测试的想法复杂化。
  • It may be possible to add custom facilities (like a locator-builder or new locator method) to the Selenium-IDE installation testers use. 可以向Selenium-IDE安装测试人员使用添加自定义工具(如定位器构建器或新定位器方法)。
  • Almost everything that goes on occurs within a single "page load" from a conventional browser perspective, even when items are saved 从传统的浏览器角度来看,几乎所有发生的事情都发生在单个“页面加载”中,即使项目被保存也是如此

Current thoughts 目前的想法

I'm considering a system where a custom locator-builder (javascript code) for Selenium-IDE will talk with our application code as the tester is recording. 我正在考虑一个系统,其中Selenium-IDE的自定义定位器构建器(javascript代码)将与测试人员正在录制的应用程序代码进行通信。 In this way, our application becomes partially responsible for generating a mostly-flexible expression (XPath or jQuery) for any given DOM element. 通过这种方式,我们的应用程序成为为任何给定DOM元素生成大多数灵活的表达式(XPath或jQuery)的部分责任。 While this can avoid requiring more training for testers, I worry it may be over-thinking things. 虽然这可以避免对测试人员进行更多的培训,但我担心这可能是过度思考的事情。

Record and Playback will not work in large scale testing. 录制和播放不适用于大规模测试。 It may work for smoke tests and small repetitive tasks. 它可能适用于烟雾测试和小型重复性任务。

Instead of trying to generate unique IDs, try to solve that with CSS based selectors. 尝试使用基于CSS的选择器来解决这个问题,而不是尝试生成唯一ID。 Generating unique ids is ideal goal but I don't think that is possible in all practical cases. 生成唯一ID是理想的目标,但我认为在所有实际情况下都不可能。

If you trying to look for custom locators, it is better to look into BDD. 如果您尝试查找自定义定位器,最好查看BDD。

Can't you use css selectors with Selenium? 你不能用selenium的css选择器吗? That seems a little more straightforward than using XPath. 这似乎比使用XPath更直接。

http://saucelabs.com/blog/index.php/2010/01/selenium-totw-css-selectors-in-selenium-demystified/ http://saucelabs.com/blog/index.php/2010/01/selenium-totw-css-selectors-in-selenium-demystified/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM