selenium tutorial testing tools

Protractor basic Example Program

Let us now create a very basic test and execute using protractor. As we know protractor needs to files spec file (test file) and conf file (configuration file).

'describe' is block of code that implements the suite and 'it'is a block with combination of commands and expectations syntax is from the Jasmine framework.

browser is a global created by Protractor, which is used for browser-level commands such as navigation with browser.get(). (To make it work with Non-AngularJs application, we should use browser.driver.get(). We will look more in detail in later tutorials)

Below is the sample Test file named 'testspec.js'

describe('angularjs homepage', function() {
  it('should have a title', function() {
    browser.get('http://angularjs.org/');

    expect(browser.getTitle()).toContain('AngularJS');
  });
});

The above simple test will navigate to an AngularJS home page and checks for its page title.

Below is the sample config file named 'conf.js'

exports.config = {
	//The address of a running selenium server.
  seleniumAddress: 'http://localhost:4444/wd/hub',
 //Here we specify the name of the specs files.
  specs: ['testspec.js']
}

How to run???

Go to the command prompt, just type 'protractor conf.js', which will start executing your test in chrome browser by default. You can also change the browser using capabilities in conf.js file. We will look into more details in later tutorials.

Note: First you need to navigate to the location where you located and then try to execute. Or else just pass the complete path to protractor as protractor G:\path\conf.js

And also before executing the test, we should make sure that selenium server is running.

The complete title is "AngularJS — Superheroic JavaScript MVW Framework". As we are trying to assert using 'toContain' which will return true. It is like 'contains' method.

Protractor pass test

In the same test file if we use 'toEqual' instaed of 'toContain' test will result as failure. Please check the error in the below image

Protractor fail test

In the above screen shot, if you observe, it is displaying a message as "Expected 'AngularJS — Superheroic JavaScript MVW Framework' to equal 'AngularJs'. It is trying to find the complete title and returns fail as we have given a partial text.

Protractor Tutorials: 

Add new comment

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Enter the characters shown in the image.

Wanted Contributers

Hello Viewer! We're a relatively a small group of writers who have combined efforts to write the articles. Well, we need more help from talented people to contribute and grow the size of articles. It's great work if you're looking for a little money on the side – make this as your Part time job.

We are mainly looking into Protractor, Cucumber, JBehave, RSpec, Behat Mink, Selenium Python or any other tool which uses selenium.

If you can contribute on any the above, Please contact us.