npm - Hur man tar skärmdumpar för varje teststeg i Protractor Cucumber TypeScript-ramverket?
Jag har två frågor. Den ena är hur man tar skärmdumpar för varje teststeg och den andra är hur man bifogar respektive skärmdumpar bredvid varje teststeg i min cucumber-html-rapport. Jag är ny på Protractor, så behöver lite hjälp.
Jag använder cucumber-reporter och jag har placerat koden där jag har placerat config-, hooks- och reporter.ts-filerna. Låt mig veta var jag behöver göra ändringarna. Tack :)
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.");
}
}
}
}