我有两个问题,一个是如何捕获每个测试步骤的屏幕截图,第二个是如何在我的cumul-html-reporter的每个测试步骤旁边附加各自的屏幕截图。一些帮助。
我正在使用Cucumber-reporter,并且已经放置了配置,钩子,reporter.ts文件的代码,让我知道需要在哪里进行更改。 谢谢:)
config.ts:
import * as path from "path";
import { browser, Config } from "protractor";
import { Reporter } from "../support/reporter";
const jsonReports = process.cwd() + "/reports/json";
export const config: Config = {
seleniumAddress: "http://127.0.0.1:4444/wd/hub",
SELENIUM_PROMISE_MANAGER: false,
baseUrl: "http://www.leafground.com/pages/Dropdown.html",
capabilities: {
browserName: "chrome",
},
framework: "custom",
frameworkPath: require.resolve("protractor-cucumber-framework"),
specs: [
"../../features/*.feature",
],
onPrepare: () => {
browser.ignoreSynchronization = true;
browser.manage().window().maximize();
Reporter.createDirectory(jsonReports);
},
cucumberOpts: {
compiler: "ts:ts-node/register",
format: "json:./reports/json/cucumber_report.json",
require: ["../../typeScript/stepdefinitions/*.js", "../../typeScript/support/*.js"],
strict: true,
tags: "(@ListOfWebelementsScenario)"
},
onComplete: () => {
Reporter.createHTMLReport();
},
};
hooks.ts:
const { BeforeAll, After, AfterAll, Status } = require("cucumber");
import * as fs from "fs";
import { browser } from "protractor";
import { config } from "../config/config";
BeforeAll({timeout: 100 * 1000}, async () => {
await browser.get(config.baseUrl);
});
After(async function(scenario) {
if (scenario.result.status === Status.FAILED) {
// screenShot is a base-64 encoded PNG
const screenShot = await browser.takeScreenshot();
this.attach(screenShot, "image/png");
}
});
AfterAll({timeout: 100 * 1000}, async () => {
await browser.quit();
});
reporter.ts:
import * as reporter from "cucumber-html-reporter";
import * as fs from "fs";
import * as mkdirp from "mkdirp";
import * as path from "path";
const jsonReports = path.join(process.cwd(), "/reports/json");
const htmlReports = path.join(process.cwd(), "/reports/html");
const targetJson = jsonReports + "/cucumber_report.json";
const cucumberReporterOptions = {
jsonFile: targetJson,
output: htmlReports + "/cucumber_reporter.html",
reportSuiteAsScenarios: true,
theme: "bootstrap",
};
export class Reporter {
public static createDirectory(dir: string) {
if (!fs.existsSync(dir)) {
mkdirp.sync(dir);
}
}
public static createHTMLReport() {
try {
reporter.generate(cucumberReporterOptions); // invoke cucumber-
html-reporter
} catch (err) {
if (err) {
throw new Error("Failed to save cucumber test results to json
file.");
}
}
}
}