그냥 질문에 언급 된 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")
}
}
}
}
, 오류를 차단하고 스크린 샷을 저장합니다 스크린 샷의 특성을 확장 모든 사양.
질문에서 언급 한 것처럼 화면 캡처()를 사용하여 주변 지역을 보완하는 것은 단언 할 때 실패 만 저장하지만 요소를 찾을 수 없어 (예 : 잘못된 선택기) 테스트가 실패하면 스크린 샷을 저장하지 않습니다.
위 코드를 사용하면 모든 실패가 스크린 샷을 저장합니다.
출처
2016-09-02 14:28:35
Tom