4

I am practicing CucumberJS with WebDriverIO and testing http://webdriver.io. I had following feature file and step definition and this was working fine.

Feature File

Feature: Application Title
    Page title should be context sensitive

    Scenario: Page loads with correct title
        When Page "/" is loaded
        Then Page title is "WebdriverIO - WebDriver bindings for Node.js"

Step Definition

const { Given, When, Then } = require('cucumber');
const assert = require('assert');

const webdriverio = require('webdriverio');

When(/^Page \"(.*)\" is loaded$/, (page) => {
    browser.url(page);
});

Then(/^Page title is \"(.*)\"$/, (title) => {
    assert(browser.title(), title);
});

But when I changed the Scenario to Scenario Outline, it stopped working with error. Following are the changes I made in feature file.

Feature File (Updated)

Feature: Application Title
    Page title should be context sensitive

    Scenario Outline: Page loads with correct title
    When Page "<url>" is loaded
    Then Page title is "<title>"

    Examples:
    | url         | title                                        |
    | /           | WebdriverIO - WebDriver bindings for Node.js |
    | /guide.html | WebdriverIO - Developer Guide                |

Console

D:\playground\webdriverio-cucumberjs>npm run e2e

> webdriverio-cucumberjs@1.0.0 e2e D:\playground\webdriverio-cucumberjs
> wdio


[13:11:45]  COMMAND     POST     "/wd/hub/session"
[13:11:45]  DATA                {"desiredCapabilities":{"javascriptEnabled":true,"locationContextEnabled":true,"handlesAlerts":true,"rotatable":true,"maxInstances":5,"browserName":"chrome","loggingPrefs":{"browser":"ALL","driver":"ALL"},"requestOrigins":{"url":"http://webdriver.io","version":"4.12.0","name":"webdriverio"}}}
[13:11:49]  INFO        SET SESSION ID d206c5af3fcb467668d5f1d21135bd5a
[13:11:49]  RESULT              {"applicationCacheEnabled":false,"rotatable":false,"mobileEmulationEnabled":false,"networkConnectionEnabled":false,"chrome":{"chromedriverVersion":"2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91)","userDataDir":"C:\\Users\\BilalM\\AppData\\Local\\Temp\\scoped_dir2072_18134"},"takesHeapSnapshot":true,"pageLoadStrategy":"normal","databaseEnabled":false,"handlesAlerts":true,"hasTouchScreen":false,"version":"65.0.3325.181","platform":"Windows NT","browserConnectionEnabled":false,"nativeEvents":true,"acceptSslCerts":false,"acceptInsecureCerts":false,"locationContextEnabled":true,"webStorageEnabled":true,"browserName":"chrome","takesScreenshot":true,"javascriptEnabled":true,"cssSelectorsEnabled":true,"setWindowRect":true,"unexpectedAlertBehaviour":""}
ERROR: Cannot read property 'steps' of undefined
chrome
Type    at CucumberEventListener.onTestStepPrepared (D:\playground\webdriverio-cucumberjs\node_modules\wdio-cucumber-framework\build\cucumberEventListener.js:186:44)
    at emitOne (events.js:101:20)
    at EventEmitter.emit (events.js:188:7)
    at TestCaseRunner.emit (D:\playground\webdriverio-cucumberjs\node_modules\cucumber\lib\runtime\test_case_runner.js:94:29)
    at TestCaseRunner.emitPrepared (D:\playground\webdriverio-cucumberjs\node_modules\cucumber\lib\runtime\test_case_runner.js:127:12)
    at TestCaseRunner.<anonymous> (D:\playground\webdriverio-cucumberjs\node_modules\cucumber\lib\runtime\test_case_runner.js:219:14)
    at next (native)
    at tryCatcher (D:\playground\webdriverio-cucumberjs\node_modules\bluebird\js\release\util.js:16:23)
    at PromiseSpawn._promiseFulfilled (D:\playground\webdriverio-cucumberjs\node_modules\bluebird\js\release\generators.js:97:49)
    at TestCaseRunner.<anonymous> (D:\playground\webdriverio-cucumberjs\node_modules\bluebird\js\release\generators.js:201:15)
    at TestCaseRunner.run (D:\playground\webdriverio-cucumberjs\node_modules\cucumber\lib\runtime\test_case_runner.js:236:22)
    at Runtime.<anonymous> (D:\playground\webdriverio-cucumberjs\node_modules\cucumber\lib\runtime\index.js:113:51)
    at next (native)
    at tryCatcher (D:\playground\webdriverio-cucumberjs\node_modules\bluebird\js\release\util.js:16:23)
    at PromiseSpawn._promiseFulfilled (D:\playground\webdriverio-cucumberjs\node_modules\bluebird\js\release\generators.js:97:49)
    at Runtime.<anonymous> (D:\playground\webdriverio-cucumberjs\node_modules\bluebird\js\release\generators.js:201:15)
[13:11:49]  COMMAND     DELETE   "/wd/hub/session/d206c5af3fcb467668d5f1d21135bd5a"
[13:11:49]  DATA                {}
------------------------------------------------------------------
[chrome #0-0] Session ID: d206c5af3fcb467668d5f1d21135bd5a
[chrome #0-0] Spec: D:\playground\webdriverio-cucumberjs\e2e\features\app-titles.feature
[chrome #0-0] Running: chrome
[chrome #0-0]
[chrome #0-0] Application Title
[chrome #0-0]
[chrome #0-0]     Page loads with correct title
[chrome #0-0]
[chrome #0-0]         Page loads with correct title
[chrome #0-0]
[chrome #0-0]
[chrome #0-0]


Cannot write xunit report: empty or invalid 'outputDir'.
Cannot write json report: empty or invalid 'outputDir'.
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! webdriverio-cucumberjs@1.0.0 e2e: `wdio`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the webdriverio-cucumberjs@1.0.0 e2e script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\#$#$#$#$\AppData\Roaming\npm-cache\_logs\2018-04-06T11_11_49_985Z-debug.log

Code is available at GitHub: https://github.com/mabilalmirza/webdriverio-cucumberjs.

Am I doing something wrong or Is this something to do with CucumberJS?

Bilal Mirza
  • 2,576
  • 4
  • 30
  • 57
  • Remove blank space between last step of your scenario and example table and try again. – Zohaib Jawaid Apr 06 '18 at 11:29
  • 1
    @ZohaibJawaid, did you read the console output at all? - It seems to be an issue with your reporting folders not existing for xunit and json. The folders that you are putting the reports and screenshots into should exist before running the tests - it wont do it on running. - or at least, that's my experience with it. It's trying to emit something to the report, which cannot be done, because the directory doesn't exist – KyleFairns Apr 06 '18 at 12:03
  • Where did you specify your 'outputDit'? – Marit Apr 07 '18 at 07:51
  • I didn't specify `outputDir` at all. I set it up using WebDriverIO cli. But this issue is not related to reporting because even if I remove xunit and junit reporters, it still fails with same error, i.e. `Cannot read property 'steps' of undefined` – Bilal Mirza Apr 09 '18 at 07:20

1 Answers1

3

It seems that, for the time being, this functionality is bugged. You can keep track of the issue on the wdio-cucumber-framework GitHub page: Here

I spent an entire day trying workarounds, but I guess we will just have to wait for the fix.

AdevaS
  • 81
  • 5