量角器:如何从测试中访问`ElementFinder`类

时间:2014-07-23 18:21:15

标签: angularjs protractor

我正在寻找一种方法来扩展量角器ElementFinder课程。有没有办法访问量角器的ElementFinder类/构造函数,所以我可以在测试中动态扩展它?

量角器暴露的所有全局变量的引用也非常有用。

1 个答案:

答案 0 :(得分:6)

我正在使用以下解决方法$('').constructor;将ElementFinder功能扩展到#1102

/**
 * Current workaround until https://github.com/angular/protractor/issues/1102
 * @type {Function}
 */
var ElementFinder = $('').constructor;

// Examples:

/**
 * Schedules a command to compute the width of this element's
 * bounding box, in pixels.
 * @return {!webdriver.promise.Promise.<number>} A promise that will
 *     be resolved with the element's width as a {@code {number}}.
 */
ElementFinder.prototype.getWidth = function() {
    return this.getSize().then(function(size) {
        return size.width;
    });
};

/**
 * Schedules a command to compute the height of this element's
 * bounding box, in pixels.
 * @return {!webdriver.promise.Promise.<number>} A promise that will
 *     be resolved with the element's height as a {@code {number}}.
 */
ElementFinder.prototype.getHeight = function() {
    return this.getSize().then(function(size) {
        return size.height;
    });
};