Protractor and Jasmine Automation Framework

Protractor and Jasmine

What is Protractor?

Protractor is an open source end-to-end testing framework for Angular and AngularJS applications, built by Google on top of WebdriverJS. It also serves as a replacement for the existing AngularJS E2E testing framework called “Angular Scenario Runner”. WebdriverJS is a Selenium webdriver API with JavaScript bindings. That means WebdriverJS API provides APIs for tests which are written in JavaScript.

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 Framework

architecture-protactor-jasmine
  • Protractor – As discussed earlier, it is a wrapper over WebDriver JS especially designed for angular apps
  • Jasmine – A behavior-driven development framework for testing the JavaScript code. We can write the tests easily with Jasmine
  • WebDriver JS – A Node JS binding implementation for Selenium 2.0/WebDriver
  • Selenium – It simply automates the browser

Jasmine

Jasmine is a behavior-driven development testing framework for JavaScript. It does not rely on browsers, DOM, or any JavaScript framework. Thus, it’s suited for websites, Node.js projects, or anywhere that JavaScript can run. A Jasmine spec represents a test case inside the test suite. This begins with a call to the Jasmine global function ‘it’ with two parameters – the first parameter represents the title of the spec and the second parameter represents a function that implements the test case.

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
Advantages
  • 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
Limitations

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
  • Knowledge of JavaScript is essential for the user, because it is available only for JavaScript
  • Only provides front-end testing because it is a UI driven testing tool

About the author

Ramakrishnan Panchapakesan

Add comment

Welcome to Miracle's Blog

Our blog is a great stop for people who are looking for enterprise solutions with technologies and services that we provide. Over the years Miracle has prided itself for our continuous efforts to help our customers adopt the latest technology. This blog is a diary of our stories, knowledge and thoughts on the future of digital organizations.


For contacting Miracle’s Blog Team for becoming an author, requesting content (or) anything else please feel free to reach out to us at blog@miraclesoft.com.

Who we are?

Miracle Software Systems, a Global Systems Integrator and Minority Owned Business, has been at the cutting edge of technology for over 24 years. Our teams have helped organizations use technology to improve business efficiency, drive new business models and optimize overall IT.