nightwatch无法找到我的步骤定义文件

时间:2018-04-04 18:33:46

标签: cucumber nightwatch.js cucumberjs

我正在为我的项目做POC。当我用下面的项目结构进行样本测试时,我面临着一个错误。对此有任何帮助非常感谢。

我的项目结构如下所示。

enter image description here

我的conf文件内容如下所示。

require('nightwatch-cucumber')({
    cucumberArgs: [
        '--require', 'features/step_definitions',
        'features',
    ]
});

module.exports = {
    output_folder : 'reports',
    custom_assertions_path : '',
    page_objects_path : 'page_objects',
    live_output : false,
    disable_colors: false,
    globals_path : '',
    selenium : {
        start_process : true,
        server_path : './bin/selenium-server-standalone-3.9.1.jar',
        log_path : '',
        host: '127.0.0.1',
        port : 4444
    },
    test_settings : {
        default : {
            launch_url : "https://<url>",
            selenium_host : '127.0.0.1',
            selenium_port : 4444,
            desiredCapabilities : {
                browserName : 'chrome',
                javascriptEnabled : true,
                acceptSslCerts : true
            }
        },
        chrome : {
            desiredCapabilities : {
                browserName : 'chrome',
                javascriptEnabled : true,
                acceptSslCerts : true
            },
            selenium : {
                cli_args : {
                    'webdriver.chrome.driver' : './bin/chromedriver/chromedriver'
                }
            }
        }
    }
};

和saturnLogin步骤文件

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


defineSupportCode( ({Given, When, Then}) => {
    Given(/^I login SATURN application with "(.*?)" and "(.*?)"$/, (user, pass) => {
        console.log("Manimaran....")
        const loginPage = client.page.saturn_login()

        return loginPage
            .navigate()
            .setValue('@userName', user)
            .setValue('@passWord', pass)
    })
})

并且package.json文件有

{
  "name": "nightwatch-poc",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "mytest": "nightwatch -e chrome"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "cucumber": "^4.1.0",
    "nightwatch": "^0.9.20",
    "nightwatch-cucumber": "^9.1.2"
  }
}

当我运行我的测试时,我收到如下错误。

λ npm run mytest

> nightwatch-poc@1.0.0 mytest C:\<user>\nightwatch-POC
> nightwatch -e chrome

Starting selenium server... started - PID:  3220

There was an error while starting the test runner:

Error: Cannot find module 'features\step_definitions\saturnLogin.js'
    at Function.Module._resolveFilename (module.js:536:15)
    at Function.Module._load (module.js:466:25)
    at Module.require (module.js:579:17)
    at require (internal/module.js:11:18)
    at C:\<user>\nightwatch-POC\node_modules\cucumber\lib\cli\index.js:163:16
    at Array.forEach (<anonymous>)
    at Cli.getSupportCodeLibrary (C:\<user>\nightwatch-POC\node_modules\cucumber\lib\cli\index.js:162:24)
    at Cli.<anonymous> (C:\<user>\nightwatch-POC\node_modules\cucumber\lib\cli\index.js:181:39)
    at Generator.next (<anonymous>)
    at Generator.tryCatcher (C:\<user>\nightwatch-POC\node_modules\bluebird\js\release\util.js:16:23)
    at PromiseSpawn._promiseFulfilled (C:\<user>\nightwatch-POC\node_modules\bluebird\js\release\generators.js:97:49)
    at Promise._settlePromise (C:\<user>\nightwatch-POC\node_modules\bluebird\js\release\promise.js:574:26)
    at Promise._settlePromise0 (C:\<user>\nightwatch-POC\node_modules\bluebird\js\release\promise.js:614:10)
    at Promise._settlePromises (C:\<user>\nightwatch-POC\node_modules\bluebird\js\release\promise.js:693:18)
    at Async._drainQueue (C:\<user>\nightwatch-POC\node_modules\bluebird\js\release\async.js:133:16)
    at Async._drainQueues (C:\<user>\nightwatch-POC\node_modules\bluebird\js\release\async.js:143:10)

npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! nightwatch-poc@1.0.0 mytest: `nightwatch -e chrome`
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the nightwatch-poc@1.0.0 mytest 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\par964\AppData\Roaming\npm-cache\_logs\2018-04-04T18_28_54_978Z-debug.log

0 个答案:

没有答案