I`m trying to use protractor with plain nodejs (not Typescript) and async functions as test callbacks.
Unfortunately an error appears telling me that these async functions are no functions.
Stacktrace:
1) some test encountered a declaration exception
Message:
Error: async function() {
await browser.get('https://www.google.com');
});
} is not a function
Stack:
Error: async function () {
await browser.get('https://www.sixt-neuwagen.de');
let blub = await ekomi.isDisplayed();
expect(blub).toBe(true);
} is not a function
at validateFunction (/<some>/<path>/projects/protractor/node_modules/jasminewd2/index.js:21:11)
at /<some>/<path>/projects/protractor/node_modules/jasminewd2/index.js:139:16
at Suite.<anonymous> (/<some>/<path>/projects/protractor/specs/index.js:5:5)
at Object.<anonymous> (/<some>/<path>/projects/protractor/specs/index.js:2:1)
at Module._compile (module.js:571:32)
at Object.Module._extensions..js (module.js:580:10)
at Module.load (module.js:488:32)
Testsuite:
describe('some test', function() {
it('should do something', async function() {
await browser.get('https://www.google.com');
});
});
Reason:
(Taken from jasminewd2 index.js)
function validateFunction(functionToValidate) {
if (functionToValidate && Object.prototype.toString.call(functionToValidate) === '[object Function]') {
return functionToValidate;
} else {
throw Error(functionToValidate + ' is not a function');
}
}
Async functions checked with Object.prototype.toString.call(functionToValidate) evaluate to [object AsyncFunction].
Env:
7.7.15.1.12.0.0I suggest abstracting out async functions to their own exported module. I'm not sure Jasmine supports async/await. Even if it does, browser.get does not return a promise, so I don't think it will work the way you'd like. Here is what I would do:
navigation module
export async function goToPage(path) {
await browser.get(address);
// you may also want to use .waitForAngular() here
}
test
// import your module with navigation
describe('some test', () => {
beforeAll((done) => {
goToPage(address).then(done);
});
it('should do a thing', () => {
// do your actual test actions and expectation here
});
});
For opening a page this might be true, but what if you want to use all the async / await goodness in your tests?
It is said that the control-flow library will be deprecated in the near future (or maybe already is) and I guess that slight changes to the jasminewd2 dependency might make the whole thing work.
Sorry, your best option for now is to use TypeScript (or Babel or some other compiler).
Seems so, i wasnt aware trat there might be a problem in some 3rd party library.
Thanks anyway for hints and suggestions!
@th3l0g4n I'm hitting this same issue. I think it would be fixed by https://github.com/angular/jasminewd/pull/87.
I hope someone from Protractor team can review my PR with potential fix for this issue.
@heathkit, I was able to use async/await (without Babel) in my protractor tests after applying angular/jasminewd#87
Thanks for the fix! I'll take a look.
I am able to use async in protractor tests with the change from angular/jasminewd#87 applied manually to my node_modules/jasminewd2/index.js file.
I think angular/jasminewd#87 is worth the bump to new patch versions of both jasminewd and protractor. This provides a path forward to conversion. Thanks!!
This ticket can be closed since https://github.com/angular/jasminewd/pull/87 is merged and new version is published.
@alexeyraspopov
Tnx for the head-up, gonna close it
I was facing the same issue; this got resolved after I uninstalled global protractor and reinstalled it and executed webdriver-manager update.
I was on protractor 5.1.1 when I faced the issue. Now I am on protractor 5.1.2 .
Most helpful comment
@heathkit, I was able to use async/await (without Babel) in my protractor tests after applying angular/jasminewd#87