量角器中的WebDriver getLocation [英] WebDriver getLocation in protractor

查看:64
本文介绍了量角器中的WebDriver getLocation的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在运行我的量角器测试时获取页面上元素的x和y值。

I'm trying to get the x and y values for an element on the page while running my Protractor test.

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

我收到的错误如'预期未定义为''。我错过了什么?

I'm getting errors like 'Expected undefined to be ''.' What am I missing?

推荐答案

显然,getLocation()会返回一个promise,因此编写调用的正确方法如下所示。

Apparently, getLocation() returns a promise, so the proper way to write the call is as below.

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

这篇关于量角器中的WebDriver getLocation的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆