如何使用TestCafe在Fail上进行屏幕截图



我试图在失败时在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");

但是如何只在失败时才这样做呢?

takeScreenshotsOnFails在较新版本中已被takeOnFails取代。

您的配置文件可能如下所示:

{
"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
}

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

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

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

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

代码是

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

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

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

您可以遵循官方文档:

测试失败时进行屏幕截图

您可以将TestCafe配置为每当测试失败。使用以下任一项:

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

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

  • runner.screenshotsAPI方法的takeOnFails参数,

runner.screenshots({
takeOnFails: true
});
  • screenshots.takeOnfails配置文件属性
{
"screenshots": {
"takeOnFails": true
}
}

相关内容

  • 没有找到相关文章

最新更新