如何使用 ScalaTest 编写验收测试?
ScalaTest 有非常好的文档,但它们很短并且没有给出示例 验收测试。
如何使用 ScalaTest 为 Web 应用程序编写验收测试?
ScalaTest has very good documentation but they are short and do not give an example of
acceptance test.
How can I write acceptance test using ScalaTest for a web application?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用 Selenium 2 可以让你取得一些进展。我将 Selenium 2 WebDriver 与发现的 Selenium DSL 的变体结合使用 此处。
最初,我更改了 DSL,以便更容易从 REPL 运行(见下文)。然而,构建此类测试的更大挑战之一是它们很快就会失效,然后成为维护的噩梦。
后来,我开始为应用程序中的每个页面创建一个包装类,并通过便捷的操作将要发送到该页面的事件映射到底层的 WebDriver 调用。这样,每当底层页面发生变化时,我只需要更改我的页面包装器,而不是更改整个脚本。这样,我的测试脚本现在以各个页面包装器上的调用来表示,其中每次调用都会返回一个反映 UI 新状态的页面包装器。看起来效果很好。
我倾向于使用 FirefoxDriver 构建测试,然后在将测试转移到我们的 QA 环境之前检查 HtmlUnit 驱动程序是否给出了可比较的结果。如果成立,那么我使用
HtmlUnit
驱动程序运行测试。这是我对 Selenium DSL 的原始修改:
Using Selenium 2 gets you some mileage. I'm using Selenium 2 WebDriver in combination with a variation of the Selenium DSL found here.
Originally, I changed the DSL in order to make it a little easier to run in from the REPL (see down below). However, one of the bigger challenges of building tests like these is that they quickly get invalidated, and then become a nightmare to maintain.
Later on, I started creating a wrapper class for every page in the application, with convenience operations mapping the event to be sent to that page to the underlying
WebDriver
invocations. That way, whenever the underling page is changing, I just need to change my page wrapper, rather than changing the entire script. With that, my test scripts are now expressed in terms of invocations on the individual page wrappers, where every invocation returns a page wrapper reflecting the new state of the UI. Seems to work out quite well.I tend to build my tests with the
FirefoxDriver
and then before rolling the test to our QA environment check if theHtmlUnit
driver is giving comparable results. If that holds, then I run the test using theHtmlUnit
driver.This was my original modification to the Selenium DSL:
ScalaTest 现在提供 Selenium DSL:
http://www.scalatest.org/user_guide/using_selenium
ScalaTest now offers a Selenium DSL:
http://www.scalatest.org/user_guide/using_selenium