1

I am evaluating Karate UI and really like it. I use it as standalone jar (as the team do not want to support Java project but is fine with JS) and am wondering how can I attach screenshots of the web app generated right when a step fails?

I have seen this question - Attaching screenshots to json report and hope it would be possible to doing something with the standalone version as well.

1 Answers1

2

If you look at the section on "hooks": https://github.com/intuit/karate#hooks

You should be able to use an afterScenario hook like this:

* configure afterScenario = function(){ if (karate.info.errorMessage) driver.screenshot() }

Works with with 0.9.5.RC4. With latest official release 0.9.4 it does not.

Edit2 - works globally with the following line in karate-config.js

    karate.configure('afterScenario', read('afterScenarioScreenshot.js'))

Where afterScenarioScreenshot.js contains the JS function from above

Peter Thomas
  • 54,465
  • 21
  • 84
  • 248
  • This works elegantly and I see in the logs that a screenshot command is made - first {"method":"Page.captureScreenshot","id":41} and than {"id":41,"result":{"data":"iVBORw0KGg...} and only after that the browser is closed. But is it saved on the disk as it is not "automatically" attached to the report? I could not find it anywhere on the disk as well. – Plamen Gospodinov Nov 26 '19 at 11:46
  • @PlamenGospodinov it should be in the report, there should be a `target` folder. actually can you try this ZIP release: https://github.com/intuit/karate/wiki/ZIP-Release - and you should find a `target/cucumber-html-reports` folder with reports – Peter Thomas Nov 26 '19 at 12:38
  • 1
    with 0.9.5.RC4 it works! With 0.9.4 not. Thanks once again for the fast answers! – Plamen Gospodinov Nov 26 '19 at 12:51