如果出现错误,我希望能够记录场景名称。我正在使用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/