Protractor 量角器+;柴

Protractor 量角器+;柴,protractor,chai,Protractor,Chai,在我的Chai测试中,我有以下几点: this.When(/^I click the (.*) button$/, function(button, next) { element(by.xpath('//input[@value="Log Out"]')).click(); next(); }); 我预计这会失败,因为我按钮的文本实际上是登录 但是,我的测试运行(甚至在浏览器显示之前)并在终端上看到: Feature: Authentication In order

在我的Chai测试中,我有以下几点:

this.When(/^I click the (.*) button$/, function(button, next) {
    element(by.xpath('//input[@value="Log Out"]')).click();
    next();
});
我预计这会失败,因为我按钮的文本实际上是登录 但是,我的测试运行(甚至在浏览器显示之前)并在终端上看到:

Feature: Authentication
    In order to protect the system
    As an owner
    I want to require authentication

Scenario: Require username      features\general\authentication.feature:6
    Given I am on the login page        ...
    When I do not enter a username      ...
    And I click the "Log in" button     ...
    Then I should receive a validation error "The Username field is required." 

Scenario: Require password
    Given I am on the login page        ...
    When I do not enter a password      ...
    And I click the "Log in" button     ...
    Then I should receive a validation error "The Password field is required."

2 scenarios (2 passed)
8 steps (8 passed)
0m00.014s
然后,我终于看到浏览器打开,测试开始通过浏览器进行

此时,我收到错误消息:

C:\Projects\NexusWeb\Develop\Nexus.Web\Nexus.Web.Tests\node_modules\selenium-webdriver\lib\atoms\error.js:108
  var template = new Error(this.message);
                 ^
NoSuchElementError: No element found using locator: By.xpath("//input[@value=\"Log Out\"]")
这当然是我所期望的

我的问题

  • 为什么我会收到一个报告说有两个场景通过了,而浏览器甚至还没有通过它们
  • 当他们都应该失败的时候,为什么他们报告通过了

  • 谢谢。

    所以,我想起来了……文档非常稀少

    我需要添加对click()的承诺:

    this.When(/^I click the (.*) button$/, function(button, next) {
        element(by.xpath('//input[@value="Log Out"]')).click().then(function() {
            next();
        });
    });