错误步骤的黄瓜步骤失败

时间:2017-08-17 14:42:23

标签: javascript selenium cucumber

以下步骤测试失败(故意):

Then(/^the 150 button has been deselected$/, function () {
    driver.sleep(5000);
    var checboxValue = driver.findElement(By.css('#app > div > div > div > div.col-xs-offset-2.col-xs-10 > div > div > div:nth-child(3) > div:nth-child(1) > div:nth-child(6) > div > label:nth-child(2) > input[type="checkbox"]'))
    checboxValue.isSelected()
      .then((val) => { return assert.equal(val, true) })
  })

但是,在命令行中,上述步骤通过,但以下步骤失败(带有正确/预期的错误消息):

When(/^Date 1 is entered$/, function () {
    var dateInput1 = driver.findElement(By.css('#app > div > div > div > div.col-xs-offset-2.col-xs-10 > div > div > div:nth-child(3) > div:nth-child(1) > div:nth-child(5) > div > div:nth-child(1) > input'));
    dateInput1.click();
    driver.sleep(8000);
    return dateInput1.sendKeys('2017-07-13');
  })

以下是命令行中的内容:

(tick)Then the 150 button has been deselected # features\step_definitions\task_2.js:23
   × When Date 1 is entered # features\step_definitions\task_2.js:30
       AssertionError: false == true
           + expected - actual

           -false
           +true

这里发生了什么?对我来说,'然后'步骤应该失败并且'当'步骤应该是蓝色的 - 在cmd行中(即在上一步失败时没有达到)。

由于

1 个答案:

答案 0 :(得分:0)

尝试使用此软件包而不是github.com/djungowski/cucumber-assert。我很确定它必须对使用它的方式做些什么。

var assert = require('cucumber-assert');

module.exports = function() {

    this.Given(/^the field E-Mail is filled with "([^"]*)"/, function (email, callback) {
        var fieldValue = this.getFieldValue('#password');
        assert.equal(fieldValue, email, 'Expected E-Mail to be ' + email).then(callback, callback);
    });

}