These days, most of the web development uses angularJS library for it’s light weight and ease of use.
protractor become popular to do end to end testing for angularJS apps.
Protractor is a node.js program built on top of WebDriverJS (selenium web driver in Java script). that simulates user actions on browser.
Why protractor?
- As Protractor is extending web driver features – Supports all features of selenium web driver and extending itself to support for angularJS.
- Provides angular specific locator strategies in addition to selenium locators .
- Auto synchronisation – Protractor waits for the page to complete current task / user actions and then moves to next line of test [No explicit waits to our test]
- But there is a catch, as protractor is asynchronous in nature, order of execution is not defined, so we need to resolve the promise, we need to use then keyword or async / await to make the test synchronised.
- Installation is quite straight forward (by use of npm command)
- Several IDEs [Free] to write protractor tests – Atom, Visual Studio code, Eclipse, Sublime text etc
- Protractor uses Jasmine or Mocha framework for syntax (popular framework used to test java script)
- Good integration with Cucumber for BDD tests.
- Can be used to test both angular and non-angular based applications
Protractor Architecture
Protractor programming language
Protractor tests can be written in java script or typescript.
Promises and control flow
As we discussed, protractor is based on WebDriverJS which is using promises,
Promise example
let test = element.all(by.css('.default__item')).then(elems => elems[2].click());
With out promise
let test = element.all(by.css('.default__item')); test[2].click();
In the above example, Protractor can pick the click operation before even identifying the element i.e execution is asynchronous in nature, to make it synchronous, we have to use then keyword or async / await.
Refer promises and control flow for more information.
References
For more information about protractor with jasmine model – follow protractor style guide
For more information on protractor, follow protractor api