Aru*_*run 4 javascript webdriver protractor
我正在尝试在运行Protractor测试时获取页面上元素的x和y值.
it('should keep the left nav links floating along with the page', function() {
var navDiv = element(by.id('pd_page_nav'));
var initTop = navDiv.getLocation().y;
var initLeft = navDiv.getLocation().x;
browser.get("en-us/learn#dpacreditresource");
var currTop = navDiv.getLocation().y;
var currLeft = navDiv.getLocation().x;
expect(initLeft).toBe('');
expect(initTop).toBe('');
expect(currLeft).toBe(initLeft);
expect(currTop).toBeGreaterThan(initTop);
});
Run Code Online (Sandbox Code Playgroud)
我得到的错误就像'预计未定义为'.' 我错过了什么?
显然,getLocation()返回一个promise,因此编写调用的正确方法如下所示.
it('should keep the left nav links floating along with the page', function () {
var initTop = 0;
var initLeft = 0;
element(by.id('pd_page_nav')).getLocation().then(function (navDivLocation) {
initTop = navDivLocation.y;
initLeft = navDivLocation.x;
browser.get("en-us/learn#dpacreditresource");
element(by.id('pd_page_nav')).getLocation().then(function (navDivLocation2) {
var currTop = navDivLocation2.y;
var currLeft = navDivLocation2.x;
expect(currLeft).toBe(initLeft);
expect(currTop).toBeGreaterThan(initTop);
});
});
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6036 次 |
| 最近记录: |