How to utilize javascript asynchronicity to speed up test execution in protractor tests other than running tests in parallel?

**Note:**This question is about utilizing core features of JavaScript language itself like asyncronicity.

I am not talking about general automation execution optimizations like no waits or parallel execution etc.


There is not much you can do at this moment, generally speaking. The asynchronicity is currently handled by the Control Flow being a queue of promises which are resolved in order one by one. WebDriverJS, which Protractor is based on, though falls under the pressure of the fast evolvement of the JavaScript ecosystem:

JavaScript has evolved in many ways since WebDriverJS was originally created. Not only did the community standardize the behavior and API for promises, but promises were added to the language itself. The next version of JavaScript, ES2017, adds support for async functions, greatly simplyfing the process of writing and maintaining asynchronous code. At this point, the benefits of the promise manager no longer outweigh its costs, so it will soon be deprecated and removed from WebDriverJS.

And, as of now, in version 4 (should be released soon), there will be no promise manager at all, it was removed from the WebDriverJS API.

The removal of the promise manager means that we should migrate to the native JavaScript features like async/await - there is a documented migration path already in place. Also, here is Protractor's documentation about using async/await.

Note that this needs Node >= 8.0 and Jasmine >= 2.7.

I have not personally tried async/await in Protractor tests and cannot talk about the performance aspect of it, but I expect the promise management part to become faster with async/await without the overhead of the WebDriver's promise manager.

I guess one other option to make the test execution faster is to turn the Angular-Protractor sync off whenever possible. This though can negatively affect the reliability and cause extra flakiness which can be mitigated with good test habits like having explicit waits.

That said, there are other, more promising (pun intended) ways of speeding up Protractor tests - like test paralellization, avoiding re-opening a browser often etc.

And, that said, keep in mind that end to end tests are slow by definition. Make sure you are not causing reliability issues by trying to solve performance problems.

| improve this answer | |
  • Thanks Alecxe, if we are not bound by control flow and self managing the promises flow , do you see a possibility then using native JavaScript features? I know I will be sounding like re- inventing the wheel but for a moment hypothecically do you see any solutions? – Vishal Aggarwal Dec 30 '17 at 15:57
  • 1
    @VishalAggarwal actually, the promise manager can be turned off and soon will not exist (selenium 4.0) - added some information to the answer, check it out. Hope this is closer to what you were originally asking about. Thanks. – alecxe Dec 30 '17 at 17:47

Test parallelization, as mentioned by @alecxe, really makes a difference; in case you're not practicing this, you'll observe the execution of the tests taking so much less time than before, so at least try, it's very easy, just add shardTestFiles: true and maxInstances: 5 to your conf.js file. Find out more here.

Another suggestion, but this is not related to the Protractor framework itself but it's a matter of test-logic, is to pre-populate site cookies which can speed up scripts, by avoiding additional site navigation, let's say, but this, of course, depends on the AUT and the e2e flows you have automated.

And also what it can be done, if your AUT is rich in images, is to disable the images to be loaded by the browser, and this will cause the rest of the web-pages to load way faster. You can achieve this by setting up a new profile for the browser and disable loading images for it, and then in the script use the new profile when starting the browser driver.

| improve this answer | |
  • Thanks Raul for your valuable suggestions.Could you please provide more technical details on pre- populating cooking and disabling images in context of Protractor.I like your suggestions. – Vishal Aggarwal Jan 1 '18 at 16:55
  • @VishalAggarwal - Such follow-ups are much better to be asked as separate questions. – Peter M. - stands for Monica Jan 2 '18 at 17:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.