cucumber - 黄瓜测试示例未运行
问题描述
我已经设置了一个工作的守夜环境,现在想使用黄瓜进行测试。我已遵循本指南:https ://www.youtube.com/watch?v=Jdlsv0CQ2CY&t=22s 。无论我尝试什么,我都无法使测试正常工作,我将其作为输出:
> 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
我有 package.json、nightwatch.conf.js、cucumber.conf.js、hackernews.feature 和 hackernews.js 文件。
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"
}
}
我该如何解决?
解决方案
您可能会在 package.json 文件中为步骤定义文件提供错误的路径,
“脚本”:{“测试”:“cucumber-js --require cucumber.conf.js --require step-definitions --format node_modules/cucumber-pretty”},
例如我的,这是我在 package,json 中的代码,
“脚本”:{“测试”:“cucumber-js --require cucumber.conf.js --require 测试--format node_modules/cucumber-pretty”},
“--require tests”:这里的“test”是我的功能文件和我的步骤定义文件所在的位置文件夹。
推荐阅读
- java - 由于未解决的依赖关系,无法创建新的 Play 项目 - SunCertPathBuilderException:无法找到有效的认证
- php - 当“session_start()”函数已经被使用时,如何在不同的页面中使用会话变量?
- python - IndexError - 使用 pytorch 实现 CBOW 的测试
- javascript - 如何更改javascript代码/函数中的日期格式输出?
- javascript - 在 MathJax 中检测是否存在要处理的 Math
- python - Jupyter notebook,如何同时运行多个单元?
- javascript - 使用 Vue.js 将 v-if 构造为 v-for 中的过滤器时遇到问题
- c++ - enable_shared_from_this 中的空弱指针
- sql-server - Microsoft SQL Server Management Studio 启动然后突然无法启动
- android-studio - Pub 包更新管理