protractor.js期望[]等于[“...”,“......”]

时间:2016-05-15 01:58:40

标签: javascript angularjs node.js protractor

我正在尝试做角度js教程,但我无法理解这个错误。 代码:           var phoneNameColumn = element.all(by.repeater('phone in phones')。column('phone.name'));

      function getNames() {
        return phoneNameColumn.map(function(elm, index) {
          return elm.getText();
        });
      }

      expect(getNames()).toEqual([
        "Motorola XOOM\u2122 with Wi-Fi",
        "Motorola XOOM\u2122"
      ]);

当我运行npm run protractor时,我看到这个错误消息预期[]等于[“Motorola XOOM \ u2122 with Wi-Fi”,“Motorola XOOM \ u2122”]

1 个答案:

答案 0 :(得分:0)

我会从使用.column()切换到:

function getColumnNames() {
    return element.all(by.repeater('phone in phones')).map(function(elm, index) {
      return elm.element(by.binding('phone.name')).getText();
    });
}

expect(getColumnNames()).toEqual([
    "Motorola XOOM\u2122 with Wi-Fi",
    "Motorola XOOM\u2122"
]);

并且,我还add a wait使测试更稳定:

var EC = protractor.ExpectedConditions;
browser.wait(EC.presenceOf(element(by.binding('phone.name'))), 5000);

expect(getColumnNames()).toEqual([
    "Motorola XOOM\u2122 with Wi-Fi",
    "Motorola XOOM\u2122"
]);