3

I'm trying to make a screenshot in Testcafe + gherkin on fail but has no success. I've setup a config file:

{
  "browsers": "firefox",
  "screenshots": {
    "path": "reports/screenshots/",
    "takeScreenshotsOnFails": true,
    "pathPattern": "${TIME}.png"
  },
  "reporter": [
    {
      "name": "spec"
    },
    {
      "name": "cucumber-json",
      "output": "reports/generatedReports/newReport.json"
    }
  ],
  "pageLoadTimeout": 1000
}

But screenshots is not appear. Other lines are working like browser etc.

Should I use:

   await t.takeScreenshot("reports/SCREENSHOT.png");

But how to do it only on fail?

Alex Skorkin
  • 4,264
  • 3
  • 25
  • 47
Olena Huk
  • 93
  • 9
  • Looks like `takeScreenshotsOnFails` is obsolete, can you try the `takeOnFails` instead? https://devexpress.github.io/testcafe/documentation/using-testcafe/configuration-file.html#screenshotstakeonfails – lostlemon Nov 19 '19 at 20:32
  • Thank you for your response! I've tried both variants but it doesn't help :( – Olena Huk Nov 20 '19 at 07:18
  • I've found way through command line adding -S -s reports/screenshots -p "${DATE}_${TIME}.png" But I'd like to make it via config file. – Olena Huk Nov 21 '19 at 07:45
  • 1
    The [`takeOnFails`](https://devexpress.github.io/testcafe/documentation/using-testcafe/configuration-file.html#screenshotstakeonfails) property works for me. My configuration file is as follows: `{ "browsers": "firefox", "screenshots": { "path": "reports/screenshots/", "takeOnFails": true, "pathPattern": "${TIME}.png" }, "reporter": [ { "name": "spec" } ], "pageLoadTimeout": 1000 }` Could you specify the testcafe version you are using? – aleks-pro Nov 25 '19 at 15:10
  • We're using "testcafe": "1.2.1" – Olena Huk Nov 28 '19 at 07:29
  • We introduced the [`screenshot`](https://devexpress.github.io/testcafe/documentation/using-testcafe/configuration-file.html#screenshots) object in version 1.6.0 . So to make the configuration file I've provided in my previous comment work update TestCafe to version 1.6.0 or later. – aleks-pro Dec 02 '19 at 11:19

4 Answers4

0

takeScreenshotsOnFails has been replaced by takeOnFails in newer versions.

Your configuration file should probably look like this:

{
  "browsers": "firefox",
  "screenshots": {
    "path": "reports/screenshots/",
    "{
  "browsers": "firefox",
  "screenshots": {
    "path": "reports/screenshots/",
    "takeOnFails": true,
    "pathPattern": "${TIME}.png"
  },
  "reporter": [
    {
      "name": "spec"
    },
    {
      "name": "cucumber-json",
      "output": "reports/generatedReports/newReport.json"
    }
  ],
  "pageLoadTimeout": 1000
}
Mate Mrše
  • 7,997
  • 10
  • 40
  • 77
0

I am not pretty sure if this is working on testcafe with gherkin. You can add this code under script into your package.json

"test:chrome": "testcafe chrome ./tests -s takeOnFails=true",

and run with command npm run test:chrome

Fatur
  • 21
  • 5
0

create a different file or append in the existing file that is .testcaferc.json

code is

{"screenshotPath": "./screennshots", 
"screenshotPathPatterns": "${DATE}_${TIME}/${FISTURE}.png"}

and inside the package.json file update the following code

"test:chrome": "testcafe chrome ./tests -s takeOnFails = true",
surender pal
  • 447
  • 6
  • 15
0

You could follow the official documentation:

Take Screenshots When a Test Fails

You can configure TestCafe to automatically take a screenshot whenever a test fails. Use either of the following:

  • the takeOnFails parameter in the -s (--screenshots) command line flag,

  • testcafe chrome tests/sample-fixture.js -s takeOnFails=true

  • the takeOnFails parameter of the runner.screenshots API method,

runner.screenshots({
    takeOnFails: true
});
  • the screenshots.takeOnfails configuration file property.
{
    "screenshots": {
        "takeOnFails": true
    }
}
blackgreen
  • 34,072
  • 23
  • 111
  • 129