Using Protractor with Angular.js
Testing is an unavoidable step in the process of web application and any kind of development in general. Protractor is a Node.js program which is opensource.It is an end-to-end testing framework for both Angular and Angular.js. It uses selenium to test. To run it on your device you need Node.js installed in your system. Protractor is built especially for testing Angular apps. It supports the Angular-specific locator strategies which help to smoothly test elements without setup effort. It s base is WebDriver Js which uses native events and browser-related drivers to communicate with your application like a user. It has automatic waiting. It can execute the next step in your test the moment the webpage finishes pending tasks. To test using protractor, first install Node.js verify the version by executing node –v. Then install npm and verify its version by executing npm version. Now install protractor after getting it from https://www.protractortest.org/#/ . The npm commands for installing Protractor and verifying version is:
npm install -g protractor
protractor --version
To run the test get update webdriver-manager , write the test, set configuration and run it.
To update webdriver-manager:
webdriver-manager update
webdriver-manager start
To write the test just copy the below code and save it as helloWorld.js.
describe('Angularjs homepage Hello World', function() {
it ('Say hello world',function() {
browser.get('https://angularjs.org');element(by.model('yourName')).sendKeys('World');
var welcomeMessage = element.all(by.tagName('h1'));
expect(welcomeMessage.get(1).getText()).toEqual('Hello World!');
});
});
Create conf.js and type the below lines to configure test setup.
exports.config = {
framework: 'jasmine',
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['helloWold.js']
}
Now run the test using command:
protractor conf.js
Comments
0 comments
Please Sign in or Create an account to Post Comments