量角器即使期望失败也能成功

时间:2018-07-20 15:49:58

标签: javascript protractor cucumber chai

我是量角器的新手,我正在准备用它和黄瓜来安装一个项目。

场景如下

  Scenario: User login
    Given the page is open
    And email is set with value n@n.com
    And password is set with value 123
    When the user click on login button
    Then home page is displayed

步骤定义已实现,login_page.js如下

var chai = require('chai').use(require('chai-as-promised'));
var expect = chai.expect;

var LoginPage = function() {

    this.get = function() {
        browser.get('https://aaa/login');
    };

    this.setEmail = function(value) {
        element(by.id('login-email')).sendKeys(value);
    };

    this.setPassword = function(value) {
        element(by.id('login-password')).sendKeys(value);
    };

    this.clickAccede = function() {
        element(by.id('login-submit')).click()
    };

    this.pageIsLoaded = function() {
        browser.waitForAngular();
        expect(browser.getTitle()).to.be.eventually.equals('page title');
    };
};

然后,当我运行场景时,我将收到以下结果

  Scenario: User login
  ✔ Given the page is open
  ✔ And email is set with value n@n.com
  ✔ And password is set with value 123
  ✔ When the user click on login button
  ✔ Then home page is displayed

1 scenario (1 passed)
5 steps (5 passed)
0m00.005s
[16:23:50] E/launcher - expected 'aaa' to equal 'page title'
[16:23:50] E/launcher - AssertionError: expected 'aaa' to equal 'page title'
[16:23:50] E/launcher - Process exited with error code 199

您可以看到断言失败,但结果返回成功。 我想念什么?

2 个答案:

答案 0 :(得分:0)

@巴拉斯 我的步骤定义

this.Then(/^shipment page is displayed$/, function (callback) {
    expect(browser.getTitle()).to.be.eventually.equals('page title');
    callback();
});

答案 1 :(得分:0)

    this.Then(/^shipment page is displayed$/, function () { return expect(browser.getTitle().then((value)=>{
console.log(value);return value;
})).to.be.eventually.equals('page title'); });

使用它并检查