4
A
回答
3
使用Selenium 2可以获得一定的里程数。我将Selenium 2 WebDriver与Selenium DSL的变体here结合使用。
最初,我改变了DSL以便使它从REPL(参见下文)运行起来更容易一些。然而,像这样构建测试的更大挑战之一是,它们很快就会失效,然后成为维护的噩梦。
稍后,我开始为应用程序中的每个页面创建一个包装类,其中便利操作将要发送到该页面的事件映射到底层的WebDriver
调用。这样,每当下层页面发生变化时,我只需要更改我的页面包装器,而不是更改整个脚本。因此,我的测试脚本现在以单个页面包装器上的调用表示,每个调用都返回一个反映UI新状态的页面包装器。似乎工作得很好。
我倾向于使用FirefoxDriver
构建我的测试,然后在将测试滚动到我们的QA环境之前,检查HtmlUnit
驱动程序是否提供了可比较的结果。如果这样,然后我使用HtmlUnit
驱动程序运行测试。
这是我原来的修改硒DSL:
/**
* Copied from [[http://comments.gmane.org/gmane.comp.web.lift/44563]], adjusting it to no longer be a trait that you need to mix in,
* but an object that you can import, to ease scripting.
*
* With this object's method imported, you can do things like:
*
* {{"#whatever"}}: Select the element with ID "whatever"
* {{".whatever"}}: Select the element with class "whatever"
* {{"%//td/em"}}: Select the "em" element inside a "td" tag
* {{":em"}}: Select the "em" element
* {{"=whatever"}}: Select the element with the given link text
*/
object SeleniumDsl {
private def finder(c: Char): String => By = s => c match {
case '#' => By id s
case '.' => By className s
case '$' => By cssSelector s
case '%' => By xpath s
case ':' => By name s
case '=' => By linkText s
case '~' => By partialLinkText s
case _ => By tagName c + s
}
implicit def str2by(s: String): By = finder(s.charAt(0))(s.substring(1))
implicit def by2El[T](t: T)(implicit conversion: (T) => By, driver: WebDriver): WebElement = driver/(conversion(t))
implicit def el2Sel[T <% WebElement](el: T): Select = new Select(el)
class Searchable(sc: SearchContext) {
def /[T <% By](b: T): WebElement = sc.findElement(b)
def /?[T <% By](b: T): Box[WebElement] = tryo(sc.findElement(b))
def /+[T <% By](b: T): Seq[WebElement] = sc.findElements(b)
}
implicit def scDsl[T <% SearchContext](sc: T): Searchable = new Searchable(sc)
}
2
ScalaTest现在提供了一个硒DSL:
相关问题
- 1. 如何编写验收测试
- 2. 如何编写异步Scala.js测试(例如使用ScalaTest)?
- 3. 如何使用Cucumber在功能级别编写验收测试?
- 4. 如何使用ScalaTest测试Dao对象
- 5. 使用specflow为Mvc4/WebApi网站编写验收测试
- 6. Scalatest - 如何测试println
- 7. 如何编写验证测试?
- 8. 试验型)scalatest
- 9. 如何使用JavaScript编写测验?
- 10. 如何在scalatest中禁用测试?
- 11. 如何使用httprouter编写测试
- 12. 为“精益”用户故事编写验收测试
- 13. 使用ScalaTest测试AKKA演员
- 14. 使用ScalaTest测试多个数据集
- 15. 如何编写JUnit测试?
- 16. 如何编写测试dataSource.getPooledConnection()
- 17. CPPUnit如何编写测试?
- 18. QuickFix验收测试
- 19. 如何在Codeception WebDriver的上下文中编写正确的PayPal验收测试?
- 20. 如何编写验证调用子例程的单元测试?
- 21. 如何编写用于设计验证方法的Rspec测试
- 22. 如何使用ScalaTest测试基于Salat的方法
- 23. 如何使用ScalaTest测试预期异常的附加属性
- 24. 如何使用Maven插件运行JUnit测试的Scalatest
- 25. 如何在ScalaTest测试中正确使用Spark?
- 26. 如何修复验收测试路线?
- 27. 如何编写作业测试用例
- 28. 如何编写测试用例Clojure中
- 29. 如何编写Controller的测试用例?
- 30. 如何编写$ q.all的测试用例
上的网页http://www.scalatest.org/getting_started_with_feature_spec给出了一个验收测试的例子。你在找什么? – paradigmatic