3

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

  • testfx-core 4.0.1-alpha
  • testfx-junit 4.0.1-alpha

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 ?

Hassam Abdelillah
  • 2,246
  • 3
  • 16
  • 37
  • 1
    have a look at DebugUtils: it comes with a bunch of methods to tailor the error output, including screenshot (not entirely certain whether that's available in 4.01, mine is something like 4.0.14 with a couple of tweaks ..) – kleopatra Feb 20 '19 at 14:00

1 Answers1

1

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).

kleopatra
  • 51,061
  • 28
  • 99
  • 211
  • I do not know if it is because of my version of testfx but i can get a failed test screenshot even with the default path. That's wierd!? I saw from souce code that the tests hava a test-fx prefix in the name of generated png. I cant find any in my file system – Hassam Abdelillah Mar 04 '19 at 13:27
  • look at the error message of the failed test: it has a line that prints the complete (absolute) path to the image file – kleopatra Mar 04 '19 at 13:49
  • I have no errors indicating a screenshot or a path of anything!. Maybe, it has something to do with the version i'm currently using – Hassam Abdelillah Mar 04 '19 at 15:16
  • maybe, can't say - but you are certain that the test fails? – kleopatra Mar 04 '19 at 15:38