【发布时间】:2015-12-08 11:10:15
【问题描述】:
如何在我的功能场景中使用标签?
如何知道调用我的函数的场景?
其实我有一种情况:
Feature: create module feature
As a admin
I want to use create module
@createModule
Given I am logged as 'ADMIN'
And I am on "/admin/create"
Then The "book_id" field should be empty
我想在我的函数中使用我的标签@createModule 然后:
this.Then(/^The "?([^"]*)"? field should be empty$/, function (el) {
if (myModule === @createModule) {
...
} else if {
...
}
return main_po.checkIsEmptyElement(this, el);
});
我想获取我的标签@createModule,以指定调用的场景或其他替代方案,我想知道哪些场景调用了我的函数。
已解决:
我补充说:
this.Before(function (scenario, callback) {
var tags = scenario.getTags();
this.current_module = tags[0].getName();
callback();
});
还有我的功能:
this.Then(/^The "?([^"]*)"? field should be empty$/, function (el) {
if (this.current_module === @createModule) {
...
} else if {
...
}
return main_po.checkIsEmptyElement(this, el);
});
【问题讨论】:
-
这是一个有趣的标签用法,但很危险:更改标签不应该对测试产生影响,它们可以自动生成,适应不同的团队等。相反,您应该添加“Given我的任务是 createModule',在这一步中,您将“createModule”存储在您的世界中:this.current_module = module
-
我正在尝试实现这样的东西。我可以知道您的示例中的“current_module”是什么吗?
标签: javascript protractor bdd cucumberjs