What is Protractor?

  • Protractor is an end-to-end test framework for AngularJS applications.
  • Protractor is a Node.js program built on top of WebDriverJS.
  • Protractor runs tests against your application running in a real browser, interacting with it as a user would.
  • Protractor supports Angular-specific locator strategies, which allows you to test Angular-specific elements without any setup effort on your part.

 Setup 

  • Download Node.JS
  • Install jdk and add path to environmental variables
  • npm install protractor -g
  • webdriver-manager update

Configuration

exports.config = {
    seleniumAddress: 'http://localhost:4444/wd/hub',
    capabilities: {
        'browserName': 'chrome'
    },

    baseUrl: 'http://localhost:4000',
    specs: ['example-spec.js'],
    jasmineNodeOpts: {
        showColors: true
    }
};

Note: Here you can mention on which port you can run test case in baseUrl and you can specify which test cases you want to run in specs if you feel too many test cases then you can specify format like spec/*.js

Writing test case 

//testsuite
describe('angularjs task list',  function()  {
    //test case
    it('should add a task',  function()  {
        browser.get('http://www.example.org');
        element(by.model('taskText')).sendKeys('write a protractor test');
        element(by.css('[value="add"]')).click();
        var  tasks  =  element.all(by.repeater('task in taskList'));
        expect(tasks.count()).toEqual(3);
        expect(tasks.get(2).getText()).toEqual('write a protractor test');
    });
});

Note:

1.Here describe and it syntax is from Jasmine framework, browser is a global created by Protractor, which is used for browser-level commands such as navigation with browser.get.

2.You can add one test suite inside other and one test case inside of other test case. It is based on how you will maintain your code.

For more usage check https://www.cronj.com/blog/testing-angular-code-using-protractor-syntax/

Running test cases

* In first command prompt

webdriver-manager start

* In second command prompt

1.If you want to run all test cases

– protractor

2.If you want to run particular test file

– protractor [file_name]

3.If you want to run particular test suite

– add d before that test suit and run protractor in terminal then it will pick only that test suite

4.If you want to run particular test case

– add i before that test case and run protractor in terminal then it will pick only that test case

Looking for AngularJS Development Company, your search ends here!

  1. Pingback: Homepage

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.