Unable to create a managed promise instance - if function written with async/await

Protractor fails with

Unable to create a managed promise instance: the promise manager has been disabled by the SELENIUM_PROMISE_MANAGER environment variable: undefined

If any function in test written in async/await way. If function is written with promise chaines - everything works ok.

Below code will fail with above error:

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;
}

Below code will work OK:

function asyncF (): promise.Promise<boolean> {
    const loginButton: ElementFinder = Utils.selectElementById('login-btn');
    return loginButton.isDisplayed();
}

I expect both code versions to work in same way

Upvotes: 1

Views: 320

Answers (2)

Found the problem. If using async/await syntax asyncF () should return Promise<T>

For return case we actually return promise.Promise<T> and seems that's why it hasn't been working for the async/await.

Summing up:

async function asyncF (): Promise<boolean> {
    const loginButton: ElementFinder = Utils.selectElementById('login-btn');
    const res = await loginButton.isDisplayed();
    return res;
}

works perfectly

Upvotes: 2

Joaquin Casco
Joaquin Casco

Reputation: 734

You could try resolving the promise in a different way using async/await

async function asyncF (): promise.Promise<boolean> {
    const loginButton: ElementFinder = Utils.selectElementById('login-btn');
    const res = await loginButton.isDisplayed();
    return res;
}

Upvotes: 0

Related Questions