【发布时间】:2014-12-17 23:13:01
【问题描述】:
在我们的项目中,我们将 Scala Specs2 与 Selenium 一起使用。 我正在尝试使用 JUnit 注释为我的测试实现屏幕截图失败机制“in a classic way (link)”,但是,该规则根本不会调用测试失败。
测试结构如下:
class Tests extends SpecificationWithJUnit{
trait Context extends LotsOfStuff {
@Rule
val screenshotOnFailRule = new ScreenshotOnFailRule(driver)
}
"test to verify stuff that will fail" should {
"this test FAILS" in new Context {
...
}
}
ScreenshotOnFailRule 如下所示:
class ScreenshotOnFailRule (webDriver: WebDriver) extends TestWatcher {
override def failed(er:Throwable, des:Description) {
val scrFile = webDriver.asInstanceOf[TakesScreenshot].getScreenshotAs(OutputType.FILE)
FileUtils.copyFile(scrFile, new File(s"/tmp/automation_screenshot${Platform.currentTime}.png"))
}
}
我知道它现在可能不起作用,因为测试没有使用 @Test 注释进行注释。 是否可以使用 JUnit @Rule 注释来注释 Specs2 测试?
【问题讨论】:
标签: scala selenium junit selenium-webdriver specs2