【发布时间】:2021-07-08 09:30:36
【问题描述】:
我正在尝试使用 Protractor 为 Angular 应用程序编写端到端测试。我正在尝试创建一个函数,该函数在访问之前等待元素出现在页面上,但出现错误:
ReferenceError: 在初始化之前无法访问“元素”
虽然我确实需要量角器中的元素。
函数在文件global.js:
const { browser, element } = require('protractor');
const global = function () {
this.getElementAsync = (element, waitTime) =>
browser.wait(() => element.isPresent(), waitTime)
.then(() => browser.wait(() => element.isDisplayed(), waitTime));
}
module.exports = new global();
我正在另一个文件中使用它:
const global = require('./global');
const { element } = require('protractor');
var someFile = function () {
this.doWhatever = async function(sec) {
const element = await global.getElementAsync(element(by.css('.some.css')), 5000); //error is thrown here
return element.click();
};
}
module.exports = new someFile();
我愿意接受所有建议/建议。
【问题讨论】:
标签: angular async-await protractor end-to-end