0
votes

Tests based on Scala Specs2.

class MyTests {

  trait Context {
    ...
  } 

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

Is there screenshot capture mechanism implemented in Specs2? Didn't found any mention of it in the official site nor here. If it's possible, would be happy to learn how to implement it.

1
Was this answer useful/correct? Can you please validate it if that's the case? - Eric

1 Answers

0
votes

There is not screen shot capture functionality in specs2.

You can simply use an Around context like this:

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
  }
} 

You can also extend the ExampleFactory to use the example description to create the screenshot path. See here in the User Guide and post messages on the mailing-list if anything is not working.