testingjavafxintegration-testingtestfx

enable screenshots feature of failed tests in testfx


I'm currently building tests for a JavaFX app with TestFX with it's following versions :

There is not much information about how to enable screeshot taking feature for failed tests and in case it is enabled by default where they are stored ?


Solution

  • Basically, it's very simple to add a screenshot to the failure message (or tailor the message to your needs in any way): the support resides in org.testfx.util.DebugUtils, f.i. saveScreenshot() takes a screenshot on failure and stores it at the default location (that's the path to the top-level project folder)

    verifyThat(myNode, myMatcher, saveScreenshot());
    

    The path is configurable by providing a custom Supplier for Path, f.i. (for win)

    verifyThat(myNode, myMatcher, 
                saveScreenshot((() -> Path.of("C:\\Temp\\testfailures", "mytest.png")), ""));
    

    Not entirely certain about version dependencies: 4.0.1 is a bit oldish (from Mar 2015), current is 4.0.15 (from Oct 2018), mine is 4.0.14 (from Aug 2018).