【问题标题】:Protractor + Chai量角器 + 柴
【发布时间】:2016-05-07 20:41:42
【问题描述】:

在我的 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\"]")

这当然是我所期望的。

我的问题...

  1. 为什么我收到报告说 2 个场景已通过,而浏览器甚至还没有通过它们?
  2. 为什么他们都应该失败时报告通过?

谢谢。

【问题讨论】:

    标签: protractor chai


    【解决方案1】:

    所以,我想通了...文档非常稀缺...

    我需要向 click() 添加一个承诺:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-15
      • 2021-02-19
      • 1970-01-01
      相关资源
      最近更新 更多