Cucumberjs: search if result failed

Challenge :

  • Perform an automatic acceptance test using selenium, webdriver, cucumberjs.
  • Find the failed acceptance test script and take a screenshot on the page
  • Save this as an artifact in the go pipeline.

It was my task for this day. I did all this by writing a script test, setting up selenium, going through pipelines and everything else.

The only problem - I could not figure out how to find the script for the failed script and take a screenshot on the page.

Problem Details : I have the following code posted in my step definitions that runs for each step of the script

//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;

World contains browser init methods.

and this is an example 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."

. - scenario, after/before . , cucumberjs, . , stepResult, , . .

isFailed() . false , . alter-ego isSuccessful(), true , .

,

  • ?
  • after()?

TDD, , , .

+4
2

,

/support/after _hooks.js

module.exports = function() {
    this.After(function (scenario, callback) {
        if (scenario.isFailed()) {
            // Do your after stuff here
        }
        callback();
    });
};

,

+5

(cucumberjs 1.x) https://github.com/cucumber/cucumber-js/blob/1.x/lib/cucumber/api/scenario.js#L27

getKeyword: function getKeyword() {
    return astScenario.getKeyword();
},
getName: function getName() {
    return astScenario.getName();
},
getDescription: function getDescription() {
    return astScenario.getDescription();
},
getUri: function getUri() {
    return astScenario.getUri();
},
getLine: function getLine() {
    return astScenario.getLine();
},
getTags: function getTags() {
    return astScenario.getTags();
},
isSuccessful: function isSuccessful() {
    return scenarioResult.getStatus() === Cucumber.Status.PASSED;
},
isFailed: function isFailed() {
    return scenarioResult.getStatus() === Cucumber.Status.FAILED;
},
isPending: function isPending() {
    return scenarioResult.getStatus() === Cucumber.Status.PENDING;
},
isUndefined: function isUndefined() {
    return scenarioResult.getStatus() === Cucumber.Status.UNDEFINED;
},
isSkipped: function isSkipped() {
    return scenarioResult.getStatus() === Cucumber.Status.SKIPPED;
},
getException: function getException() {
    return scenarioResult.getFailureException();
},
getAttachments: function getAttachments() {
    return attachments;
},
clearAttachments: function clearAttachments() {
    attachments = [];
},
+1

Source: https://habr.com/ru/post/1545930/


All Articles