ちょうど最終的な答えを私は質問に記載されたthis postからのアプローチに基づいて問題を解決できる方法を書いています。
要するに、解決策はこのようになりました(疑似コード)。
trait Screenshots extends FunSpec {
...
override def withFixture(test: NoArgTest): Outcome = {
val outcome = test()
// If the test fails, it will hold an exception.
// You can get the message with outcome.asInstanceOf[Failure].exception
if (outcome.isExceptional) {
// Implement Selenium code to save the image using a random name
// Check: https://stackoverflow.com/questions/3422262/take-a-screenshot-with-selenium-webdriver
}
outcome
}
}
class MySpec extends Screenshots {
...
describe("Scenario A") {
describe("when this") {
it("the field must have value 'A'") {
// It will save a screenshot either if the selector is wrong or the assertion fails
driver.findElement(By.id("elementA")).getAttribute("value") should be ("A")
}
}
}
}
この時点から、Screenshot特性を拡張するすべての仕様はエラーを傍受し、スクリーンショットを保存します。
質問に記載されているように、周囲の領域をwithScreenshot()で補うだけで、アサーションでの失敗のみを保存しますが、要素が見つからないためにテストが失敗したときにスクリーンショットを保存しません。
上記のコードでは、すべての失敗がスクリーンショットを保存します。
出典
2016-09-02 14:28:35
Tom