我有这个步骤定义,检查页面中是否存在由CSS选择器标识的元素:
this.Then(/The element with selector "([^"]*)" should be present/, function(elementSelector, callback){
var selectedElement = element(by.css(elementSelector));
expect(selectedElement.isPresent()).to.eventually.equal(true, "Can't find the element with selector '" + elementSelector + "' that should be present").and.notify(callback);
});
我想知道是否可以在另一个步骤定义中调用此步骤定义。例如,在用于填充文本区域的步骤定义中,该方法可能是有用的。在这种情况下,我想知道在尝试填充之前文本区域是否存在于页面中。
提前谢谢!
答案 0 :(得分:1)
古老的问题,但是对于后来发现这个问题的人...
早期,Cucumber的创建者是enthusiastic about nesting steps,但是他们later repented themselves of ever creating the feature却建议将功能组合在一起。按照Aslak的示例,这在javascript中特别容易做到:
function x_is_something(x, cb) {
console.log('x', x);
cb();
}
Given(/x is (.*)/, x_is_something);
Given(/super x/, function(cb) {
x_is_something(97, cb);
});
这就是为什么原始Cucumber-Ruby的许多变体从不支持此功能,而其创建者have even discussed removing it却不支持此功能。