node.js - 如何从 cucumber js中获取场景名称?

标签 node.js cucumberjs

如果出现错误,我希望能够记录场景名称。我正在使用cucumber.js 和 Node 。

Feature file

Scenario: As me I can go to google

Given that I have a computer

When I go to google

Then I see wondrous stuff


我已经尝试了下面的代码,但名称作为空字符串返回。
When(/^I go to google$/, (scenario) => {
// do something
var scenarioName = scenario.name;
});
通过逐步执行代码,我可以看到它是一个函数。
它有:
[[FunctionLocation]] = 对象
[[范围]] = 范围(6)
长度 = 2
名称=""

最佳答案

似乎您不能在 Given 或 When 中执行此操作,必须在 Before 或 After Hook 中完成:

Before((scenario) => {
const scenarioName = scenario.name;
console.log(`${scenarioName}`);
});

关于node.js - 如何从 cucumber js中获取场景名称?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51746919/

相关文章:

html - 使用 wkhtmltopdf Node 模块转换为 pdf 时,表行被剪切

node.js - 如何在 puppeteer 中处理多个窗口?

protractor - 为什么 cucumber Protractor 不会完全忽略没有要运行的标签的特征文件?

cucumber Js : is it possible to define more than one "World"

javascript - TypeScript + Cucumber 问题 : Error: function timed out after 10000 milliseconds

database - CucumberJS 超时错误。我可以在我的步骤中设置 "setDefaultTimeout"吗?

node.js - 在不重新启动 "server"的情况下编码 node.js

node.js - 表示 res.redirect() 不执行任何操作

javascript - 定位器无效错误

json - 在nodejs中从json设置模型值