Automation by Jasmine and Protractor
Automation by Jasmine and Protractor
Automation by Jasmine and Protractor
Protractor
Jasmine
It is a behavior driven development framework for testing javascript.
It does not depend upon any other javascript frameworks and DOM
Syntax:
describe(‘name of your test suite’, function(){
//Collection of Specs
})
Example:
xdescribe(‘name of disabled suite’, function() {})
Jasmine - Specs
Jasmine Spec is used to test a specific block using assertions
Syntax:
Syntax:
expect(true).toBe(true);
Example:
Expect(true).not.tobe(false);
Jasmine – Assertions Types
toBe()
toBeDefined()
toEqual()
toBeTruthy()
toContain()
toMatch()
toBeLessThan()
toThrow()
Protractor
It is an end-to-end testing framework for angular apps. It focuses on testing the
actual functionality of the application
It has integrated mechanism to detect the pending tasks which relives the developer
to write wait/sleep
It has webdriver-manager which is used to start the instance of the selenium server to
initiate the end-to-end testing
Protractor Vs Selenium
Selenium cannot detect the extra html attributes of angular like ng-repeater, ng-
controller ng-model etc., using selenium code
Protractor is built using javascript on top of nodejs. Hence it can easily detect the
angular attributes which makes it perfect e2e testing of angular applications
Prerequisites:
1. nodejs (latest)
2. Jasmine framework
Npm command:
npm i –g protractor
Updating webdriver
Webdriver-manager update
Starting webdriver
Webdriver-manager start
Protractor – Writing Tests
Protractor needs spec file and config file
Spec file contains the test cases which needs to be validate by protractor
Config file contains the setup required by protractor to start executing test cases
Config file consists of the location of selenium webdriver address and spec file
Protractor – Config file
Sample config file:
exports.config = {
seleniumAddress: ‘http://localhost:4444/wd/hub’,
specs: [‘spec.js’],
capabilities: {
’browserName’: ‘chrome’
}
beforeLaunch: function(){
//Delete logs
},
onPrepare: function(){
//Set browser dimensions, jasmine reporters
}
}