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.
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.
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 .
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;
});
};
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With