Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Protractor: How to access the `ElementFinder` class from within a test

i'm looking for a way to extend protractor's ElementFinder class from within a test. Is there a way to access protractor's ElementFinder class/constructor so i would be able to extend it dynamically from within a test?

A reference of all global variables exposed by protractor would also be very helpfull.

like image 584
Joel Kornbluh Avatar asked Jul 23 '14 18:07

Joel Kornbluh


People also ask

How do you use the ElementFinder on a protractor?

The ElementFinder can be treated as a WebElement for most purposes, in particular, you may perform actions (i.e. click, getText) on them as you would a WebElement. Once an action is performed on an ElementFinder, the latest result from the chain can be accessed using the then method.

Which method is used to find all elements in protractor?

Protractor exports a global function element , which takes a Locator and will return an ElementFinder. This function finds a single element - if you need to manipulate multiple elements, use the element. all function. The ElementFinder has a set of action methods, such as click() , getText() , and sendKeys .


1 Answers

I'm using below workaround $('').constructor; to extend ElementFinder features until #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;
    });
};
like image 166
Leo Gallucci Avatar answered Oct 30 '22 10:10

Leo Gallucci