Can Selenium take a screenshot on test failure with JUnit?

后端 未结 3 823
悲哀的现实
悲哀的现实 2020-12-06 04:38

When my test case fails, especially on our build server, I want to take a picture / screenshot of the screen to help me debug what happened later on. I know how to take a s

3条回答
  •  余生分开走
    2020-12-06 05:04

    A few quick searches led me to this:

    http://blogs.steeplesoft.com/posts/2012/grabbing-screenshots-of-failed-selenium-tests.html

    Basically, he recommends creating a JUnit4 Rule that wraps the test Statement in a try/catch block in which he calls:

    imageFileOutputStream.write(
        ((TakesScreenshot) driver).getScreenshotAs(OutputType.BYTES));
    

    Does that work for your problem?

提交回复
热议问题