2014-07-23 2 views
7

sto cercando un modo per estendere la classe ElementFinder del goniometro da un test. Esiste un modo per accedere alla classe/costruttore ElementFinder del goniometro in modo da poterlo estendere dinamicamente all'interno di un test?Goniometro: come accedere alla classe `ElementFinder` da un test

Un riferimento di tutte le variabili globali esposte dal goniometro sarebbe anche molto utile.

risposta

6

Sto utilizzando la soluzione alternativa $('').constructor; per estendere le funzionalità di ElementFinder fino a #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; 
    }); 
}; 
+1

FYI, ElementFinder sembra essere esposti ora: https://github.com/angular/protractor/pull/1633 & https://github.com/angular/protractor/issues/1584 – Snekse

+1

Cool! puoi fornire tutti i passaggi? cosa 'pretendere' e così via? Può essere in una nuova risposta per esempio;) –