1

I have setup a working nightwatch environment and now want to use cucumber for testing. I have followed this guide: https://www.youtube.com/watch?v=Jdlsv0CQ2CY&t=22s. No matter what I try I cannot get the test to work, I get this as output:

> cucumberpractice@1.0.0 test /Users/kieran/Documents/cucumberPractice
> cucumber-js --require cucumber.conf.js --require step-definitions --format node_modules/cucumber-pretty

Feature: Hacker News Search

  Scenario: Searching Hacker News
    Given I open Hacker News's home page
    ? undefined
    Then the title is "Hacker News"
    ? undefined
    And the Hacker News search form exists
    ? undefined

Warnings:

1) Scenario: Searching Hacker News # features/hackernews.feature:3
   ? Given I open Hacker News's home page
       Undefined. Implement with the following snippet:

         Given('I open Hacker News\'s home page', function () {
           // Write code here that turns the phrase above into concrete actions
           return 'pending';
         });

   ? Then the title is "Hacker News"
       Undefined. Implement with the following snippet:

         Then('the title is {string}', function (string) {
           // Write code here that turns the phrase above into concrete actions
           return 'pending';
         });

   ? And the Hacker News search form exists
       Undefined. Implement with the following snippet:

         Then('the Hacker News search form exists', function () {
           // Write code here that turns the phrase above into concrete actions
           return 'pending';
         });


1 scenario (1 undefined)
3 steps (3 undefined)
0m00.000s
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! cucumberpractice@1.0.0 test: `cucumber-js --require cucumber.conf.js --require step-definitions --format node_modules/cucumber-pretty`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the cucumberpractice@1.0.0 test 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!     /Users/kieran/.npm/_logs/2019-09-13T20_22_09_135Z-debug.log

I have package.json, nightwatch.conf.js, cucumber.conf.js, hackernews.feature and hackernews.js files.

const { client } = require('nightwatch-api');
const { Given, Then } = require('cucumber');

Given(/^I open Hacker News's home page$/, () => {
    return client
        .url('https://news.ycombinator.com/')
        .waitForElementVisible('body', 1000);
});

Then(/^the title is "([^"]*)"$/, title => {
    return client.assert.title(title);
});

Then(/^the Hacker News search form exists$/, () => {
    return client.assert.visible('input[name="q"]');
});
Feature: Hacker News Search

Scenario: Searching Hacker News

  Given I open Hacker News's home page
  Then the title is "Hacker News"
  And the Hacker News search form exists
const chromedriver = require('chromedriver');

module.exports = {
    "src_folders": ["tests"],
    test_settings: {
    default: {
      webdriver: {
        start_process: true,
        server_path: chromedriver.path,
        port: 4444,
        cli_args: ['--port=4444']
      },
      desiredCapabilities: {
        browserName: 'chrome'
      }
    }
  }
};
{
  "name": "cucumberpractice",
  "version": "1.0.0",
  "description": "Cucumber framework",
  "main": "index.js",
  "scripts": {
    "test": "cucumber-js --require cucumber.conf.js --require step-definitions --format node_modules/cucumber-pretty"
  },
  "repository": {
    "type": "git",
    "url": "git+https://github.com/BinaryJava/nightwatch-testing.git"
  },
  "author": "Kieran Marriott",
  "license": "ISC",
  "bugs": {
    "url": "https://github.com/BinaryJava/nightwatch-testing/issues"
  },
  "homepage": "https://github.com/BinaryJava/nightwatch-testing#readme",
  "devDependencies": {
    "chromedriver": "^76.0.1",
    "nightwatch": "^1.2.2"
  },
  "dependencies": {
    "cucumber": "^5.1.0",
    "cucumber-pretty": "^1.5.2",
    "nightwatch-api": "^2.3.0"
  }
}

How do I fix this?

2 Answers2

0

you might giving the path wrong for step definition file in your package.json file,

"scripts": { "test": "cucumber-js --require cucumber.conf.js --require step-definitions --format node_modules/cucumber-pretty" },

for example my, here is my code in package,json,

"scripts": { "test": "cucumber-js --require cucumber.conf.js --require tests --format node_modules/cucumber-pretty" },

"--require tests": here "test" is the location folder where my feature file and my step definition files are exist.

0

Instead of Scenario: Searching Hacker News you have to put Scenario Outline: Searching Hacker News to add Examples

ylev
  • 2,313
  • 1
  • 23
  • 16