量角器:在另一个步骤定义中调用步骤定义

问题描述 投票:2回答:1

我有这个步骤定义,检查页面中是否存在由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);
 });

我想知道是否可以在另一个步骤定义中调用此步骤定义。例如,在用于填充文本区域的步骤定义中,该方法可能是有用的。在这种情况下,我想知道在尝试填充之前文本区域是否存在于页面中。

先感谢您!

javascript testing protractor
1个回答
1
投票

老问题,但对于后来发现这个问题的人来说......

黄瓜的创造者在早年是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

© www.soinside.com 2019 - 2024. All rights reserved.