Task:
That was my task for the day. I have done all of that with writing the scenario test, selenium setup, go pipelines, and everything else needed.
The only problem is - I could not get a way to figure out how can I find a failing scenario step and take a screen shot of the page.
Problem details: I have the following code placed in my step definitions, which is run for every scenario step
//file: features/setpdefinitions/common.step.js
var commonWrapper = function commonWrapper() {
this.World = require('../support/world').World;
this.Before(function (next) {
this.initBrowser(next);
});
this.After(function (next) {
this.browser.quit(next);
});
this.StepResult(function (event, callback) {
var stepResult = event.getPayloadItem('stepResult');
console.log(stepResult.isFailed());
callback();
});
};
module.exports = commonWrapper;
the World
contains the browser initiation methods.
and, this is a sample feature scenario that I am testing
Feature: Forgot Password
As a user of Booking My account
I want to reset my password
So that I can login to my account when I forget my password
Scenario: On unsuccessful entering invalid email id
Given I am on forgot password page
When I enter invalid email "invalidemail-someDomain.com"
And click submit button
Then I should see validation message "Please enter a valid email."
the problem is with the context data. I somehow could not get the scenario
passed to the after/before method as the first argument. I tried the code given in the cucumberjs source but could not succeed. So, I moved onto adding the stepResult
method, which run every time a step is completed. A relatively similar approach.
As per documentation, the isFailed()
method returns a boolean based on the step result. but, I always get a false
no matter the step failed or passed. I tried its alter-ego isSuccessful()
which returns a true
no matter what.
so,
I'm relatively new to TDD, but hey it been a great experience so far.
What you need is an after hook
Create a file features/support/after_hooks.js
module.exports = function() {
this.After(function (scenario, callback) {
if (scenario.isFailed()) {
// Do your after stuff here
}
callback();
});
};
Note that this is only executed after every feature
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With