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

Joe*_*luh 7 angularjs protractor

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

量角器暴露的所有全局变量的参考也非常有用.

Leo*_*cci 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;
    });
};
Run Code Online (Sandbox Code Playgroud)