gpt4 book ai didi

javascript - Protractor 中的 WebDriver getLocation

转载 作者:搜寻专家 更新时间:2023-11-01 05:05:15 27 4
gpt4 key购买 nike

在运行我的 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);
});

我收到类似“Expected undefined to be”这样的错误。我错过了什么?

最佳答案

显然,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);
});
});
});

关于javascript - Protractor 中的 WebDriver getLocation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23084537/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com