У меня два вопроса. Один из них - как сделать снимки экрана для каждого шага теста, а второй - как прикрепить соответствующие скриншоты рядом с каждым моим шагом теста в моем cucumber-html-reporter. Я новичок в транспортире, так что нужно некоторая помощь.
Я использую cucumber-reporter и поместил код, в который я поместил файлы config, hooks, 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.");
}
}
}
}