"未定义不是函数“;在.to Be功能

"Undefined is not a function" at .toBe fucntion

本文关键字:to Be 功能 quot 未定义 函数      更新时间:2023-09-26

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

我在得到"未定义不是函数"。下面是我的代码:试图获得元素的偏移位置:

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); 
     }); 
});

黄瓜和茉莉是互斥的。

如果您还没有,您应该使用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");