gpt4 book ai didi

angularjs - Protractor:如何从测试中访问 `ElementFinder` 类

转载 作者:行者123 更新时间:2023-12-03 06:53:32 25 4
gpt4 key购买 nike

我正在寻找一种从测试中扩展 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com