For running our tests we will use Protractor. Protractor is an end-to-end test framework for AngularJS applications.
We will use an existing Selenium grid to run our tests.

You will need NodeJS to install Protractor. You can download it from here:

To install Protractor in command prompt go to your project directory and type:

npm install protractor

or you can install Protractor globally by typing then next:

npm install -g protractor

Here is a simple test:

describe('angularjs homepage', function() {
	beforeEach(function() {
	    // before function
	afterEach(function() {
	    // after function
  it('test title', function() {
    var firstNumber = element(by.model('first'));
    var secondNumber = element(by.model('second'));
    var goButton = element('gobutton'));
    var options = element.all(By.css('select option:nth-child(2)'));

Running the test requires a config file. The config file should contain your selenium grid address and the name of the tests you want to run.

exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['test.js']

To run the test on a specific browser you can add the capabilities option to your config file:

exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['test.js'],
  capabilities: {
	    browserName: 'firefox'

To run the tests more than once on multiple browsers you can do the next:

exports.config = {
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: ['test.js'],
	multiCapabilities: [{
		browserName: 'firefox',
	}, {
		browserName: 'chrome',

To run the test enter the next line into the command prompt in your project root directory. If you installed Protractor locally:

node node_modules\protractor\bin\protractor config\conf.js

or if you installed Protractor globally:

protractor config\conf.js

After running the test it will tell you did the test pass in the command prompt. You can see the test results on the image below


Posted By Ivan Konjević

Leave a Reply

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>