Closed mike-mccormick closed 3 years ago
@mike-mccormick ,Technically, if you don't want to capture failure screenshot by default, you can use saveScreenshot
provided by nightwatch
itself.
After(async function (scenario) {
if (scenario.result.status === 'failed') {
const uniqueScenario = `${scenario.pickle.name.replace(/[^a-zA-Z0-9]/g, '')}`;
const filename = `./reports/${uniqueScenario}/${uniqueScenario}.png`;
await client.saveScreenshot(`${filename}`);
this.attach(fs.readFileSync(path.resolve(filename)), 'image/png');
}
});
Otherwise, getNewScreenshots
(provided from nightwatch-api) is quite convenient and will
After(async function (scenario) {
getNewScreenshots().forEach(file => this.attach(fs.readFileSync(file), 'image/png'));
}
});
Also,getNewScreenshot
will only get you 1 screenshot at the very end of your test, since you config
"on_failure" : true,
"on_success" : true,
"on_error" : true,
If you plan to get it in every steps, you will want to use the saveScreenshot
approach and also try to save it to a unique name so it does not overwrite the screenshot you have.
Thank you @icloudphil for the details.
Closing it as there is no further activity..
Hi,
I'm trying to add screenshots to test steps manually, using
client.SaveScreenshot()
. I'm not having any trouble getting the screenshot to save (provided I specify a path) but I can't figure out how to get these picked up in the cucumber report.I've got
After
setup exactly as the Cucumber Reporters section of the docs.If anyone knows of a way to manually add screenshots to the report on demand, or have them save always (even on success) I'd really appreciate it.
I'm using Nightwatch (running Chromedriver), Nightwatch-API (which is awesome btw) +CucumberJS and cucumber-html-reporter.
I'm using nightwatch, nightwatch-api, cucumber and cucumber-html-reporter.
Thanks!
Expected Behavior
Using
client.SaveScreenshot()
inside the step definition, andgetNewScreenshots()
insideAfterAll
in cucumber.conf.js, screenshots also get added to the cucumber report.Context
Your Environment
nightwatch.json -
test_settings
cucumber.conf.js -
After
The step definition I'm testing against:
npm script I'm running
package.json