3

我正在尝试在失败时在 Testcafe + gherkin 中制作屏幕截图,但没有成功。我已经设置了一个配置文件:

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

但是没有出现截图。其他线路像浏览器等一样工作。

我应该使用:

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

但是如何只在失败时做到这一点?

4

4 回答 4

0

takeScreenshotsOnFailstakeOnFails较新的版本中已被.

您的配置文件应该如下所示:

{
  "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
}
于 2020-06-16T10:05:51.953 回答
0

我不太确定这是否适用于带有小黄瓜的 testcafe。您可以在脚本下将此代码添加到您的 package.json

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

并使用命令运行npm run test:chrome

于 2020-06-16T13:03:54.920 回答
0

您可以按照官方文档

测试失败时截屏

您可以将 TestCafe 配置为在测试失败时自动截取屏幕截图。使用以下任一:

  • ( ) 命令行标志中的takeOnFails参数,-s--screenshots

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

  • API方法的takeOnFails参数,runner.screenshots

runner.screenshots({
    takeOnFails: true
});
  • 配置screenshots.takeOnfails文件属性。
{
    "screenshots": {
        "takeOnFails": true
    }
}
于 2021-06-04T11:57:22.963 回答
0

创建一个不同的文件或附加到现有文件.testcaferc.json

代码是

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

并在package.json文件中更新以下代码

"test:chrome": "testcafe chrome ./tests -s takeOnFails = true",
于 2021-01-04T10:32:31.683 回答