Protractor and Jasmine
What is Protractor?
Protractor is a Selenium-based test framework that interacts with Selenium server and WebDrivers such as ChromeDriver, GeckoDriver, SafariDriver, etc. to simulate the user actions. It also works as a solution integrator that combines powerful technologies such as NodeJS, Selenium, Jasmine, WebDriver, Cucumber, Mocha, etc. Along with testing the AngularJS application, it can also be used to write automated regression tests for normal web applications. This framework allows us to test our applications like a real user as it runs the test using an actual browser.
The test scripts send commands to Selenium server which in turn communicates with the browser driver and executes the commands (perform actions). Next is the assertion framework, Protractor supports various assertions frameworks such as Jasmine, Mocha, etc. This assertion framework helps us to validate or verify the values, in turn, the test will be marked as pass or fail. In short, Protractor, WebdriverJS, Selenium Server, Browser Driver and Assertion Framework provides the infrastructure for writing and executing your end-to-end tests.
- Protractor – As discussed earlier, it is a wrapper over WebDriver JS especially designed for angular apps
- WebDriver JS – A Node JS binding implementation for Selenium 2.0/WebDriver
- Selenium – It simply automates the browser
Working with Protractor
Protractor framework works in conjunction with Selenium to provide an automated test infrastructure for simulating a user’s interaction with an AngularJS application that is running in a browser or mobile device.
- Step 1 – Write test scripts. It can be done with the help of Jasmine, Mocha or Cucumber
- Step 2 – Run the tests, which can be done with the help of Protractor. It is also called test runner
- Step 3 – Manage the browsers using Selenium
- Step 4 – Invoke browser APIs with the help of Selenium WebDriver
- As an open-source tool, Protractor is very easy to install and setup
- Works well with Jasmine framework to create tests
- Supports test-driven development (TDD)
- No need to add waits and sleeps: as the webpage finishes pending tasks, Protractor executes the next steps of the testing process by automatically connecting with the AngularJS application
- Offers all the advantages of Selenium WebDriver
- Supports parallel testing through multiple browsers
- Provides the benefit of auto-synchronization
- Test execution is faster
- It has a certain advantage in case of an angular specific locator strategy. It provides more options to work with Angular directives (i.e. angular specific locator strategy). Sometimes it is difficult to capture web elements in AngularJS applications using Selenium Web driver. Protractor supports Angular-specific locator strategies, which allows you to test Angular-specific elements without any setup effort
Protractor has a few limitations which are as follows,
- Does not uncover any verticals in browser automation because it is a wrapper for WebDriver JS
- Only provides front-end testing because it is a UI driven testing tool