Typescript 无法创建托管承诺实例-如果使用async/await编写函数

Typescript 无法创建托管承诺实例-如果使用async/await编写函数,typescript,promise,async-await,jasmine,protractor,Typescript,Promise,Async Await,Jasmine,Protractor,量角器因故障而失效 无法创建托管承诺实例:承诺管理器已 已被SELENIUM\u PROMISE\u MANAGER环境变量禁用: 未定义 如果测试中有任何函数是以异步/等待方式编写的。 如果函数是用承诺链编写的,那么一切都正常 以下代码将因上述错误而失败: it('Inner', async function () { await browser.get(this.getRootPath()); await asyncF(); // Fails here }); async

量角器因故障而失效

无法创建托管承诺实例:承诺管理器已 已被SELENIUM\u PROMISE\u MANAGER环境变量禁用: 未定义

如果测试中有任何函数是以异步/等待方式编写的。 如果函数是用承诺链编写的,那么一切都正常

以下代码将因上述错误而失败:

it('Inner', async function () {
    await browser.get(this.getRootPath());
    await asyncF(); // Fails here
});

async function asyncF (): promise.Promise<boolean> {
    const loginButton: ElementFinder = element(by.id('login-btn'));
    const res = await loginButton.isDisplayed();
    return res;
}
it('internal',异步函数(){
等待browser.get(this.getRootPath());
等待asyncF();//此处失败
});
异步函数asyncF():promise.promise{
const login按钮:ElementFinder=element(by.id('login-btn');
const res=wait loginButton.isDisplayed();
返回res;
}
以下代码将正常工作:

function asyncF (): promise.Promise<boolean> {
    const loginButton: ElementFinder = Utils.selectElementById('login-btn');
    return loginButton.isDisplayed();
}
函数asyncF():promise.promise{ 常量登录按钮:ElementFinder=Utils.selectElementById('login-btn'); 返回loginButton.isDisplayed(); }
我希望两个代码版本以相同的方式工作

您可以尝试使用
async/await

async function asyncF (): promise.Promise<boolean> {
    const loginButton: ElementFinder = Utils.selectElementById('login-btn');
    const res = await loginButton.isDisplayed();
    return res;
}
异步函数asyncF():promise.promise{ 常量登录按钮:ElementFinder=Utils.selectElementById('login-btn'); const res=wait loginButton.isDisplayed(); 返回res; } 找到了问题。 如果使用异步/等待语法,则
asyncF()
应返回
Promise

对于
return
案例,我们实际上返回了
promise.promise
,这似乎就是为什么它不适用于async/await

总结:

async function asyncF (): Promise<boolean> {
    const loginButton: ElementFinder = Utils.selectElementById('login-btn');
    const res = await loginButton.isDisplayed();
    return res;
}
异步函数asyncF():Promise{ 常量登录按钮:ElementFinder=Utils.selectElementById('login-btn'); const res=wait loginButton.isDisplayed(); 返回res; }
完美地工作

我猜是因为op没有添加一个MCVE,他们还需要等待
Utils。selectElementById
@Liam,对不起,也需要显示该函数-它的实现
元素(by.id(selector))