cucumber / cucumber-js

Cucumber for JavaScript
https://cucumber.io
MIT License
5.07k stars 1.09k forks source link

Running multiple features with cucumberjs and webdriver on nodejs and typescript #2299

Closed vikramjb closed 1 year ago

vikramjb commented 1 year ago

[Update] I tried a similar test with MochaJs and it worked quite well. So the problem seems to be something specific with CucumberJs.

I am new to the cucumber land so apologies if I am not posting on the right channel. Please correct me and I will post the accordingly.

I create a test project with wdio cli ("npm init wdio@latest") accepting all default arguments, except for the below options

  1. Test Framework => Cucumber
  2. Typescript

Here's my package.json

{
  "name": "my-new-project",
  "type": "module",
  "devDependencies": {
    "@wdio/cli": "^8.11.2",
    "@wdio/cucumber-framework": "^8.11.0",
    "@wdio/local-runner": "^8.11.2",
    "@wdio/spec-reporter": "^8.11.2",
    "chromedriver": "^114.0.2",
    "cucumber-html-reporter": "^7.1.1",
    "ts-node": "^10.9.1",
    "typescript": "^5.1.6",
    "wdio-chromedriver-service": "^8.1.1"
  },
  "scripts": {
    "wdio": "wdio run ./wdio.conf.ts"
  },
  "dependencies": {
    "wdio-cucumberjs-json-reporter": "^5.1.5"
  }
}

Rest all were default options on the CLI. Press enter all the way. The initial code got created and ran the test project with npm run wdio

And it ran the default test without an issue. Then I introduced another feature/step definition and page object as follows.

togin.feature

Feature: The Google Test

  Scenario Outline: As a user, I can browse google

    Given I am on the google page

togins.ts

import { Given, When, Then } from '@wdio/cucumber-framework';

import GooglePage from '../pageobjects/google.page.js';

Given('I am on the google page', async () => {
    GooglePage.open();
});

google.page.ts

import { ChainablePromiseElement } from 'webdriverio';

import Page from './page.js';

class GooglePage extends Page {

    public open () {
        return browser.url('https://google.com')
    }
}

export default new GooglePage();

Then I ran the command again. The default feature (login.feature) ran without a problem but for some reason the framework is not running this second feature I introduced and for the life of me I can't figure out what's wrong. Here's my wdio conf

specs: [
    './features/**/*.feature'
],

require: [
     './features/step-definitions/steps.ts',
    './features/step-definitions/togins.ts'
],

Anytime I run I end up getting

[0-1] 2023-07-12T06:26:00.652Z INFO webdriver: RESULT null
2023-07-12T06:26:00.803Z DEBUG @wdio/local-runner: Runner 0-1 finished with exit code 1
[0-1] FAILED in chrome - file:///C:/Projects/SourceTrials/cucumberwdtrials/features/togin.feature

There is no error that pops up regardless of the log setting I have in wdconf. That feature works without any issues if that's the only feature running otherwise it just runs the other feature and skips the new feature I introduced. Does anybody have any idea what the problem could be?

davidjgoss commented 1 year ago

As you're using WebdriverIO and not Cucumber itself, you'll need to raise this over there https://github.com/webdriverio/webdriverio