webdriverio / cucumber-boilerplate

Boilerplate project to run WebdriverIO tests with Cucumber
http://webdriver.io
MIT License
533 stars 317 forks source link

Hooks do not run anymore #201

Closed inspiraller closed 5 years ago

inspiraller commented 6 years ago

Issue description

Hook don't seem to run anymore.

Steps to reproduce

These are my files:

wdio.conf.js

exports.config = {
    specs: ['./src/features/*.feature'],
    exclude: [],
    deprecationWarnings: false,
    maxInstances: 5,
    capabilities: [{
      maxInstances: 5,
      browserName: 'chrome'
    }],
    sync: true,
    logLevel: 'error',
    coloredLogs: true,
    screenshotPath: './errorShots/',
    baseUrl: 'http://localhost:8080',
    waitforTimeout: 10000,
    connectionRetryTimeout: 90000,
    connectionRetryCount: 3,
    services: ['selenium-standalone'],
    framework: 'cucumber',
    reporters: ['spec'],
    cucumberOpts: {
        backtrace: false,
        compiler: [
            'js:babel-register',
        ],
        failAmbiguousDefinitions: true,
        failFast: false,
        ignoreUndefinedDefinitions: false,
        name: [],
        snippets: true,
        source: true,
        profile: [],
        require: [
            './src/steps/given.js',
            './src/steps/then.js',
            './src/steps/when.js',
            './src/steps/hooks.js',
        ],
        snippetSyntax: undefined,
        strict: true,
        tagExpression: 'not @Pending',
        tagsInTitle: false,
        timeout: 20000,
    },
    before: function before() {
        const chai = require('chai');

        global.expect = chai.expect;
        global.assert = chai.assert;
        global.should = chai.should();
    }
};

hooks.js

console.log('hooks.js');
module.exports = function() {
  console.log('before Before');
  this.Before("@beforeAllScenarios",function (event, callback) {
    console.log('@beforeAllScenarios');
    callback();
    });
    this.Before({tags: ["@beforeAllScenarios"]} ,function (event, callback) {
    console.log('@beforeAllScenarios');
    callback();
    });
};

feature

Feature: Sample Snippets test
    As a developer
    I should be able to use given text snippets

    @beforeAllScenarios
    Scenario: open URL
        Given the page url is not "http://webdriverjs.christian-bromann.com/"
        And   I open the url "http://webdriverjs.christian-bromann.com/"
        Then  I expect that the url is "http://webdriverjs.christian-bromann.com/"
        And   I expect that the url is not "http://google.com"

package.json file

{
  "name": "project-with-internal-cucumber-testing",
  "version": "1.3.2",
  "description": "project with internal cucumber testing",
  "scripts": {
    "test": "wdio ./wdio.conf.js"
  },
  "keywords": [
    "webdriverio",
    "cucumber",
    "test",
    "selenium"
  ],
  "license": "MIT",
  "dependencies": {
    "babel-jest": "~23.0.0-alpha.0",
    "babel-polyfill": "~6.26.0",
    "babel-preset-es2015": "~6.24.0",
    "babel-register": "~6.26.0",
    "chai": "~4.1.2",
    "forever": "~0.15.3",
    "jest": "~22.1.0",
    "node-run-cmd": "^1.0.1",
    "wdio-cucumber-framework": "~1.1.0",
    "wdio-phantomjs-service": "~0.2.2",
    "wdio-selenium-standalone-service": "~0.0.9",
    "wdio-spec-reporter": "~0.1.2",
    "webdriverio": "4.12.0"
  }
}

Expected behavior

I expect console.log = hooks.js I expect console.log = Before I expect console.log = @beforeAllScenarios

Actual behavior

I get console.log = hooks.js and nothing else. module.exports does not seem to run at all. I have tried using es6 format, with fat arrows but does not make any difference.

Issue occurred on browser/platform

I am using windows 7, node 8.9.4 This used to work for me a year ago but was using an older version of node with the following package.json dependencies:

 "dependencies": {
    "babel-polyfill": "~6.20.0",
    "babel-preset-es2015": "~6.18.0",
    "babel-register": "~6.18.0",
    "chai": "~3.5.0",
    "cucumber": "^1.3.1",
    "eslint": "~3.13.1",
    "eslint-config-airbnb-base": "~11.0.1",
    "gulp": "^3.9.1",
    "gulp-util": "^3.0.8",
    "gutil": "^1.6.4",
    "lodash": "^4.17.4",
    "node-notifier": "^5.1.2",
    "require-all": "^2.2.0",
    "wdio-cucumber-framework": "~0.2.15",
    "wdio-json-reporter": "^0.2.0",
    "wdio-junit-reporter": "^0.3.0",
    "wdio-phantomjs-service": "~0.2.2",
    "wdio-selenium-standalone-service": "~0.0.7",
    "wdio-spec-reporter": "~0.0.5",
    "webdriverio": "~4.6.1"
  }
}

I suspect some updates to the hooks have affected it with wdio-cucumber-framework but after half a day researching have not found a working solution.

christian-bromann commented 5 years ago

We updated the boilerplate, please check if you still experience this issue. Thanks!