Skip to main content

AngularJS Web Application Automation with Protractor Tool

The dynamics of web development have changed over the years. The HTML single page coding with CSS styling is an obsolete method now. One of the open source front end web application framework is the JavaScript based AngularJS, which has been in the industry for around 6 years now.
  • What reason do we need Protractor Framework for?
Protractor is a node.js program that is used to write end-to-end test. The tests are written in javascript to simulate user stories on a web browser. Protractor is effectively built upon webdriver so a lot of stuff we do on protractor will seem very similar.
JavaScript is utilized as a part of all web applications. As the applications develop, JavaScript additionally increments in size and many-sided quality. In such case, it turns into a troublesome situation for Testers to test the web application for different situations.
In some cases, it is hard to catch the web components in AngularJS applications utilizing JUnit or Selenium WebDriver.
Protractor is a NodeJS program which is composed in JavaScript and keeps running with Node to recognize the web components in AngularJS applications, and it additionally utilizes WebDriver to control the program with client activities.
  • What reason wouldn’t bediscovered in Angular JS web components utilizing Normal Selenium Web driver?
Precise JS applications have some additional HTML properties like ng-repeater, ng-controller, ng-display and so on, which are excluded in Selenium locators. Selenium can’t recognize those web components utilizing Selenium code. Along these lines, Protractor on the highest point of Selenium can deal with and controls those qualities in Web Applications.
The protractor is a conclusion to end testing system for Angular JS based applications. While most structures center on leading unit tests for Angular JS applications, Protractor centers on testing the genuine usefulness of an application.
  • Before we start Protractor, we need to install the following:
Selenium
NPM (Node.js)
Protractor Installation
  1. Open command prompt and type “npm install –g protractor” and hit Enter.
  2. Check the installation and version using “Protractor –version.” If successful it will show the version as like in below screenshot. If not, perform the step 1 again.
  3. Update the Web driver.
    webdriver-manager update

    webdriver-manager start

    Now, if you go to the following URL (http://localhost:4444/wd/hub/static/resource/hub.html) in your browser, you will actually see the Web driver manager running in the background.
  • Sample AngularJS application testing using Protractor
Protractor needs two files to run, a spec file and configuration file.
Configuration file: This File helps protractor to where the test files are placed (specs.js) and to talk with Selenium server (Selenium Address). Chrome is the default browser for Protractor.
Spec file: This File contains the logic and locators to interact with the application.
Configuration file:
// An example configuration file.
exports.config = {
directConnect: true,
// Capabilities to be passed to the webdriver instance.
capabilities: {
‘browserName’: ‘firefox’
},
// Framework to use. Jasmine is recommended.
framework: ‘jasmine’,
// Spec patterns are relative to the current working directory when
// protractor is called.
specs: [‘Example_spec1.js’],
// Options to be passed to Jasmine.
jasmineNodeOpts: {
defaultTimeoutInterval: 30000
}
};
Spec file:(This is the sample script which is by default present in our directory)
describe(‘angularjs homepage’, function() {
it(‘should greet the named user’, function() {
browser.get(‘http://www.angularjs.org’);
element(by.model(‘yourName’)).sendKeys(‘Julie’);
var greeting = element(by.binding(‘yourName’));
expect(greeting.getText()).toEqual(‘Hello Julie!’);
});
describe(‘todo list’, function() {
vartodoList;
beforeEach(function() {
browser.get(‘http://www.angularjs.org’);
todoList = element.all(by.repeater(‘todo in todoList.todos’));
});
it(‘should list todos’, function() {
expect(todoList.count()).toEqual(2);
expect(todoList.get(1).getText()).toEqual(‘build an AngularJS app’);
});
it(‘should add a todo’, function() {
varaddTodo = element(by.model(‘todoList.todoText’));
varaddButton = element(by.css(‘[value=”add”]’));
addTodo.sendKeys(‘write a protractor test’);
addButton.click();
expect(todoList.count()).toEqual(3);
expect(todoList.get(2).getText()).toEqual(‘write a protractor test’);
});
});
});
  • Execution of the Code
To begin with, we will change the registry way or explore the envelope where the conf.js and spec.js are set in our framework.
Follow the following step.
  1. Open the command prompt.
  2. Make sure selenium web driver manager is up and running. For that give the command as “webdriver-manager start” and hit Enter.
  3. Open a new command prompt and give the command as “protractor conf.js” to run the configuration file.

(Reference link: https://docs.npmjs.com/)
Source: AngularJS Web Application Automation

Comments

Popular posts from this blog

GraphQL With Ruby

Now a day’s most of the web or mobile applications fetch data from server which is stored in a database. REST API provides an interface to stored data that require by the applications. GraphQL is a query language for REST API's not for server databases. It is database agnostic and effectively can be used in any context where an API is used. GraphQL provide platform for declarative data fetching where client need to specify what data needs from API in response. Instead of multiple endpoints that return fixed data structures, a GraphQL server only exposes a single endpoint and responds with precisely the data a client asked for. GraphQL minimizes the amount of data that needs to be transferred over the network and improves applications operating under these conditions. Introduction to GraphQL API on Ruby on Rails Start with adding gem in Gemfile gem ‘graphql’ Run command bundle install Run command rails generate graphql:install Above command will add gr

Best In Place Gem In Ruby On Rails Tutorial

The best_in_place gem is the easiest solution for in place editing in Ruby on Rails. This gem provides functionality of “in place editing” in ruby on rails without writing any extra ajax code. It supports text inputs, textarea, select dropdown, checkboxes, jQuery UI Datepickers, etc. Also Displays server-side validation Installation Steps of “best_in_place” Gem : Installing best_in_place is very easy and straight-forward. Just begin including the gem in your Gemfile: gem ‘best_in_place’ After that, specify the use of the jquery and best in place javascripts in your application.js, and optionally specify jquery-ui if you want to use jQuery UI datepickers: //= require jquery //= require best_in_place //= require jquery-ui //= require best_in_place.jquery-ui Then, just add a binding to prepare all best in place fields when the document is ready: $(document).ready(function() { /* Activating Best In Place */ jQuery(".best_in_place").best_in_place(); });

Data scraping in Ruby on Rails using Nokogiri and Mechanize Gem

What is Data scraping? Website/Data  Scraping  is a technique to operating large amounts of  data  from websites whereby the  data  is extracted and displayed in own sites or it can be stored to a File/Database. Data scraping is basically used where the websites does not provides API. Some Applications do not provide API to collect records. For the same , Data Scraping technique is used. The data can be scraped using Nokogiri Gem. The steps are required: Add the gem “gem ‘nokogiri’, ‘~> 1.8’, ‘>= 1.8.1'” . Then run the bundle install Add the “require ‘nokogiri'” , “require ‘open-uri'” line where you will write the code for the scraping. The controller of the page will look like below: The view of the code of view page will look like : The result in our application will look like: Mechanize Gem in rails The Mechanize library is used for automating interaction with websites. Mechanize automatically stores and sends cookies, follo