0

当前行为

无法识别步骤定义......无论我尝试什么,当我运行 nightwatch 时,我的功能和步骤都会返回为未定义。

预期/期望的行为

我的 step_definitions 文件夹中的代码被执行。

环境:

  • nightwatch-黄瓜版本:9.1.3
  • 守夜人版本:0.9.21
  • 黄瓜版本:6.0.5
  • Selenium_server 版本:3.141.59
  • Phantomjs-预建版本:2.1.16
  • Node.js 版本:10.17.0

包.json

    {
      "name": "nightwatchcucumbertest",
      "version": "1.0.0",
      "description": "Test the setup of nightwatch and cucumber",
      "main": "index.js",
      "scripts": {
        "test": "nightwatch"
      },
      "author": "Mark Strohfus",
      "license": "ISC",
      "devDependencies": {
        "cucumber": "^6.0.5",
        "nightwatch": "^0.9.21",
        "nightwatch-cucumber": "^9.1.3",
        "phantomjs-prebuilt": "^2.1.16",
        "selenium-server": "^3.141.59"
      },
      "dependencies": {
        "cucumber": "^6.0.5",
        "phantomjs-prebuilt": "^2.1.16",
        "selenium-server": "^3.141.59"
      }
    }

nightwatch.conf.js

var seleniumServer = require('selenium-server')
var phantomjs = require('phantomjs-prebuilt')
var nightwatchCucumber = require('nightwatch-cucumber')

// Handles the runner, location of feature files and step definitions,
// and closing of nightwatch
var nightwatchCucumberConf = {
    runner: 'nightwatch',
    featureFiles: 'features',
    stepDefinitions: 'step_definitions',
    closeSession: 'afterFeature'
}

module.exports = {
    // Loads nightwatch-cucumber configuration into main nightwatch.js conf
    src_folders: [nightwatchCucumber(nightwatchCucumberConf)],
    custom_commands_path: '',
    custom_assertions_path: '',
    page_objects_path: '',
    live_output: false,
    disable_colors: false,


    // Sets configuration for Selenium Server
    selenium: {
        start_process: true,
        server_path: seleniumServer.path,
        host: '127.0.0.1',
        port: 4444
    },


    // Sets config options for different testing environments defined by the user
    test_settings: {
        default: {
            launch_url: 'https://moduscreate.com',
            silent: true,
            desiredCapabilities: {
                browserName: 'chrome',
                javascriptEnabled: true,
                acceptSslCerts: true
            },
            'screenshots': {
                enabled: true,
                on_error: true,
                on_failure: true,
                path: '/screenshots'
            }
        },
        firefox: {
            desiredCapabilities: {
                browserName: 'firefox',
                javascriptEnabled: true,
                acceptSslCerts: true
            }
        }
    }
}

特征/about.feature

Feature: Modus About Page
    To establish that our website has an About Page
    As a user, I want to ensure that our Home page has a link to the about page


    Scenario: Verify About Page Link
        Given I open the Modus Create home page
        And the title is "Modus Create - HTML5 Application Development & Training"
        Then the About Page link exists

step_definitions/about.js

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

    Given('I open the Modus Create home page', function () {
        client
            .url('https://moduscreate.com')
            .waitForElementVisible('body', 1000);
        return 'pending';
      });

    Given('the title is {string}', function (string) {
        client.assert.title(title);
        return 'pending';
      });

    Then('the About Page link exists', function () {
        client.assert.elementPresent('a[href="/about"]');
        return 'pending';
    });

运行守夜人的输出

Starting selenium server... started - PID:  13800
UUU

Warnings:

1) Scenario: Verify About Page Link # features\modusAbout.feature:6
   ? Given I open the Modus Create home page
       Undefined. Implement with the following snippet:

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

   ? And the title is "Modus Create - HTML5 Application Development & Training"
       Undefined. Implement with the following snippet:

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

   ? Then the About Page link exists
       Undefined. Implement with the following snippet:

         Then('the About Page link 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

true
'''
4

1 回答 1

0

我强烈建议从 nightwatch-cucumber 插件转移到 nightwatch-api。

关于您面临的问题,我在您的配置文件中看不到任何与黄瓜相关的设置,这将有助于跑步者识别步骤定义文件。下面是一个链接,它可能会让您了解它需要什么。

http://mucsi96.github.io/nightwatch-cucumber/#passing-additional-cli-options-for-cucumberjs

https://github.com/mucsi96/nightwatch-cucumber/blob/master/examples/simple-example/nightwatch.conf.js#L5

干杯!

于 2020-02-14T11:52:53.207 回答