我正在寻找一种在测试中扩展 Protractor 的ElementFinder
类的方法。有没有一种方法可以访问 Protractor 的ElementFinder类/构造函数,因此我可以从测试中动态扩展它?
Protractor 暴露的所有全局变量的引用也将非常有帮助。
最佳答案
我正在使用以下解决方法$('').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;
});
};
关于angularjs - Protractor :如何从测试中访问 `ElementFinder`类,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24918028/