【问题标题】:Capturing screenshot on Specs2 (Scala) tests捕获 Specs2 (Scala) 测试的屏幕截图
【发布时间】:2014-12-15 09:32:06
【问题描述】:

基于 Scala Specs2 的测试。

class MyTests {

  trait Context {
    ...
  } 

  "test number 1" should {
    "render stuff amazingly" in new Context {
      ...validations...
    }
  }

Specs2 中是否实现了截屏机制? 在官方网站和这里都没有找到任何提及它。如果可能的话,很乐意学习如何实现它。

【问题讨论】:

  • 这个答案有用/正确吗?如果是这样,请您验证一下吗?

标签: scala automation specs2


【解决方案1】:

specs2 中没有截屏功能。

您可以像这样简单地使用Around 上下文:

trait Screenshot {
  // take a screenshot and store it under the given path
  def takeScreenshot(path: String): Unit = ???
}

trait AroundEach with Screenshot {

  // return a unique path
  def screenshotPath: String = ???

  def around[R : AsResult](r: =>Result): Result = {
    // execute the result
    val result = AsResult(r)
    if (!result.isSuccess) {
      val screenshot = takeScreenshot(screenshotPath)
      result.update(_+"\nScreenshot at"+screenshot)
    } else result
  }
} 

您还可以扩展ExampleFactory 以使用示例描述来创建屏幕截图路径。请参阅用户指南中的here,如果有任何问题,请在邮件列表中发布消息。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-04-03
    • 2011-10-13
    • 1970-01-01
    • 2012-01-20
    相关资源
    最近更新 更多