webdriverio-boneyard / wdio-cucumber-framework

A WebdriverIO v4 plugin. Adapter for Cucumber testing framework.
MIT License
77 stars 61 forks source link

scenario fail status method doesn't work for afterScenario hook #108

Closed ezwanharun closed 6 years ago

ezwanharun commented 6 years ago

Hi all, Currently I tried to taking a screenshots if my test was failed. However the afterScenario hook seem like doesn't able to identify which test is failed and passed. Below was my dependencies that I used:

"wdio-cucumber-framework": "^2.0.0",
"cucumber": "^4.0.0",

afterScenario: function afterScenario(results) { if (results.status === "failed") { browser.saveScreenshot("./allure-results/"); } },

ezwanharun commented 6 years ago

I noticed that afterScenario hook doesn't contained results status value compared to afterSteps as below:

status: 'passed'

This caused screenshot functionality for that specific scenario been taken several times if the test is been failed in the middle or beginning of the steps. Suggesting to add this config to afterScenario.

BorisOsipov commented 6 years ago

"wdio-cucumber-framework": "^1.1.0", is it correct? can you try to update to 2.0.0

ezwanharun commented 6 years ago

I'm using 2.0.0 release

ezwanharun commented 6 years ago

@BorisOsipov any update on this?

BorisOsipov commented 6 years ago

@ezwanharun no updates. feel free to investigate and propose a PR

wswebcreation commented 6 years ago

Don't think this is an issue. Since cucumber 3 or 4 they changed the scenarioResult, this should work

After((scenarioResult)=>{
    if (scenarioResult.result.status === Status.FAILED) {
        browser.saveScreenshot()
    }
});

To check it just log the scenarioResult

wswebcreation commented 6 years ago

@BorisOsipov and @ezwanharun

I've checked it and the scenarioResult will return this

{
  "sourceLocation": {
    "uri": "test/cucumber/test.feature",
    "line": 10
  },
  "pickle": {
    "tags": [],
    "name": "Click on Developer Guide",
    "language": "en",
    "locations": [
      {
        "line": 10,
        "column": 3
      }
    ],
    "steps": [
      {
        "text": "I go on the website \"http://webdriver.io\"",
        "arguments": [],
        "locations": [
          {
            "line": 4,
            "column": 11
          }
        ]
      },
      {
        "text": "I click on link \"=Developer Guide\"",
        "arguments": [],
        "locations": [
          {
            "line": 11,
            "column": 10
          }
        ]
      },
      {
        "text": "should the title of the page be \"WebdriverIO - Developer Guide\"",
        "arguments": [],
        "locations": [
          {
            "line": 12,
            "column": 10
          }
        ]
      }
    ]
  },
  "result": {
    "duration": 978,
    "status": "passed"
  }
}

Meaning you need to check scenarioResult.result.status to get the status. This was for as far I can see a breaking change in CucumberJS 3, so not an issue in this wdio-cucumber-framework and thus this issue could be closed

BorisOsipov commented 6 years ago

@wswebcreation Thanks for your help in investigating this issue!