“未定义不是一个功能”在.toBe fucntion

时间:2015-12-16 00:38:17

标签: javascript angularjs protractor

我正在编写一个测试来自动化场景,使用PROTRACTOR:

我得到“未定义不是函数”在.toBe下面是我的代码:尝试获取元素的偏移位置:

this.Then(/^I should have ONLY LOGO available on main page$/, function () { 
    element(by.id('mainPage')).getLocation().then(function (navDivLocation) { 
        var currTop = navDivLocation.y; 
        var currLeft = navDivLocation.x; 

        expect(currLeft).toBe(0); 
        expect(currTop).toBe(0); 
     }); 
});

1 个答案:

答案 0 :(得分:3)

黄瓜和茉莉花是mutually exclusive

如果您还没有,则应使用Chai断言库:

expect(currLeft).to.equal(0); 
expect(currTop).to.equal(0); 

要断言不同Protractor函数返回的promise,请使用Chai-as-promised库 - 您可以在expect()内传递promise。例如:

expect(elm.getText()).should.eventually.equal("my text");