Protractor Introduction

Protractor is a Node.js (Node.js is an open source, cross-platform runtime environment for server-side and networking applications) program that supports the Jasmine, Mocha, and Cucumber test frameworks.

Protractor is an open source functional automation framework (also known as End to End testing framework) especially designed to verify the health of AngularJS web applications. Protractor uses Selenium WebDriver to drive browsers and simulate user’s interaction with an AngularJs application running in a browser.

Protractor uses Jasmine (which is a behavior-driven development framework for testing JavaScript code) for its test syntax.

Protractor wants two files to run, the test or spec file, and the config file. We will try to understand more in later tutorials.

To define simply spec file is like a test file. We can have multiple test files (spec files) and call them as Test Suite.

And configuration file, we need to tell Protractor where the test files (specs) are located, and where to talk to Selenium Server and set up the browsers. And pass the parameters to the spec files

Here is how the test file (spec file) looks like:

describe("A test suite", function() {
  it("Should show something", function() {
    expect(some text).toEqual(some text);
  });
});

describe: A test begins with 'describe' with two parameters: a string and a function. The string is a name or title for a spec. The function is a block of code that implements the suite.

it: Which is like describe takes a string and a function. The string is a title for this spec and the function is the spec, or test.
it blocks describes the requirements of the application with a combination of commands and expectations. Commands tell Protractor to do something with the application such as navigate to a page or click on a particular button. To Assert, here 'Expect' tells Protractor to assert something such as the title of the page or the current URL etc.

Here is the simple configuration file looks like

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

seleniumAddress: Need to pass the address of a running selenium server.
specs: Need to pass the location of the spec files located.

Now let us proceed to set up protractor and start executing the tests.

Protractor Tutorials: 

Comments

Please provide some more details about protractor working like how to switch on different windows, how to select a value from drop down etc

var handlePromise = browser.driver.getAllWindowHandles();

handlePromise.then(function(handles) {
var popUpHandle = handles[1]; // Change to new handle
browser.driver.switchTo().window(popUpHandle);
//browser.sleep(4000);
browser.waitForAngular();
var popUpHandleFinal = browser.driver.getWindowHandle();

Thanks a lot for you tutorial.. i followed and ran my first protractor script..Success!!
I would like to know how feasible to use Protractor for " Functional Regression Automation..? u

Plz provide the same with small video presentation and code also.

Thanks in advance.

Add new comment

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.