Protractor is a JavaScript library. On the top
of selenium web driver, they created a wrapper of JavaScript. It is mainly used
for angularJS application. AngularJS is a kind of JavaScript framework used to
develop web application. It is used to handle the dynamic content. Which have
different locator like ‘Ng-model’ which is missing in selenium web driver. So
we use protractor for automating such application.
For set up protractor in your system you need
to download and install the following component.
1.NPM(node.js) download
Download the npm installer from the website
2.Protractor installation
Run the command ‘npm install –g protractor
3.JDK installation
Download the installer from the Java website
4.Webdriver manager update
Run the command ‘webdriver-manager update’
5.Start Webdriver manager from the command
line
Run the command ‘webdriver-manager start
How to Write the project/Script?
1.Download Visual Studio Code
2.Create a folder in the system
3.Open the command prompt and go to
the folder
4.Run the command ‘npm init’
5.Open the visual studio code. Created
folder should be displayed with ‘package.json’ file and add the dependencies
for protractor and jasmin in the ‘package.json’.
Package.json file is a file like
pom.xml in the maven project.It is used to add the dependencies like below
{
"name": "test",
"version":
"1.0.0",
"description":
"test code",
"main": "index.js",
"dependencies":
{
"protractor":
"5.4.2",
"jasmine":
"3.4.0"
},
"scripts":
{
"test": "echo
\"Error: no test specified\" && exit 1"
},
"author":
"Jithin",
"license":
"ISC"
}
6.Create a new configuration file(Conf.js)
exports.config={
seleniumAddress:'http://localhost:4444/wd/hub',
specs: ['spec.js']
}
7.Create a specification file(Spec.js) for writing the test cases
describe('Protractor
Website', function()
{
it('enter the name', function()
{
browser.get('https://angularjs.org/');
element(by.model('yourName')).sendKeys('Tom');
var text=element(by.xpath('/html/body/div[2]/div[1]/div[2]/div[2]/div/h1'))
expect(text.getText()).toEqual('Hello Tom!');
});
});
describe('Protractor title Test',function()
{
it('should have a title',function(){
browser.get('http://juliemr.github.io/protractor-demo/');
expect(browser.getTitle()).toEqual('Super
Calculator');
browser.driver.sleep(3000);
element(by.model('first')).sendKeys('Selenium');
browser.driver.sleep(3000);
});
});
8.You can run this sample script by
running he command ‘protractor config.js’ in the terminal