33

What are the differences? What are the advantages of using one over the other for an Angular project?

Nightwatch.js vs Protractor

alecxe
  • 414,977
  • 106
  • 935
  • 1,083
Atav32
  • 1,488
  • 3
  • 23
  • 30
  • 2
    This is something I was considering to ask (in a bit different fashion), but it doesn't really fit the SO format and doesn't follow the rules. – alecxe Dec 04 '14 at 20:38
  • 3
    Where would you rather have it? QA StackExchange? I think asking for the differences and advantages is objective enough. – Atav32 Dec 04 '14 at 20:43
  • 2
    I would rather paraphrase the question to be smth like: `Are there any drawbacks or benefits to use nightwatch.js for testing an angular app?` and focus on what are you losing if not using `protractor` - may be that would make a better fit - though I am not sure about that either - once I've got [my question](http://stackoverflow.com/questions/26987238/npm-isntall-command) closed as an opinion-based - still not sure why. Hope the answer helps. – alecxe Dec 04 '14 at 20:58

2 Answers2

22

If you are working on an AngularJS project, the choice is simple - Protractor:

  • it is being made specifically for angular apps (though it can be used for non-angular apps also)
    • supports angular-specific locator strategies (like by.model, by.repeater etc)
    • waits for angular to start up during the page load (sync)
  • it is being actively maintained and improved mostly by google developers with a close cooperation with an angular team - this means that protractor follows the angular release cycle and new changes
alecxe
  • 414,977
  • 106
  • 935
  • 1,083
  • 6
    I'm also considering Nightwatch vs Protractor and can't help wonder if it is really as straightforward as this? Shouldn't the technology choices of the web application under test be irrelevant to the end to end tests? Using angular specific locator strategies sounds like an entry point to tightly coupling the tests to the code. – KarlPurk Jan 14 '16 at 09:20
  • 2
    @KarlPurk I think we would quickly go philosophical about it. Protractor is just a convenient wrapper around WebDriverJS with several really neat Angular specific features. It does not mean you have to use them or you cannot test other non-angular applications. Protractor remains a generic e2e tool that you can use for e2e testing of any web application.. – alecxe Jan 14 '16 at 16:44
3

There are a few more differences that weren't laid out in the top answer.

The big one for me is, as of now, protractor doesn't support phantomJS (http://www.protractortest.org/#/browser-setup#setting-up-phantomjs). I planned on integrating automation in to the CI system, but with protractor I would have to set up a windows VM to run the tests.

Other benefits of nightwatch:

  • Asserts are done automatically.
  • Clean console output, you could hand off to anyone.
  • Test reports are automatically generated and saved to a /reports directory.

Protractor pros:

  • The angular-specific locators that protractor supports is very powerful and could help immensely with creating stable tests.
  • WaitForAngular is also very helpful.

EDIT: Since the time I wrote this comment and present day our team has happily switched over to using cypress.io. If you are deciding test frameworks I highly recommend checking it out: https://www.cypress.io/

Kevin S
  • 471
  • 3
  • 6
  • Why do you test end to end of your code with phantomjs? Also notice that Protractor has been used by many people through the CI and does not need a Windows VM. I have done it so many times on Linux boxes. You just need xvfb to run it. – Ali Motevallian Jan 12 '18 at 16:47
  • 1
    Actually i dont use phantomsjs anymore. Chrome now supports headless mode and the maintainer of phantomsjs is no longer updating it. – Kevin S Jan 29 '18 at 20:06