Tuesday, 31 May 2016

setting up protractor

Download and install NodeJS. http://nodejs.org/download/.
To verify your installation, please type in the command

npm –version                          

Install Protractor Globally:

Open the command prompt and type in the following command to install protractor globally. (Using npm)
This will install two command line tools, protractor and webdriver-manager.

npm install -g protractor

To verify your installation, please type in the command

Protractor   --version

If Protractor is installed successfully then the system will display the installed version. Otherwise you will have to recheck the installation.

Grid Setup:

The webdriver-manager is a helper tool to easily get an instance of a Selenium Server running. Use it to download the necessary binaries with:

webdriver-manager update

Now start up a server with:

webdriver-manager start

This will start up a Selenium Server and will output a bunch of info logs. Your Protractor test will send requests to this server to control a local browser. You can see information about the status of the server at http://localhost:4444/wd/hub.

Write a Simple Test: ( save as FirstSpec.js)

describe('angularjs homepage todo list', function() {
  it('should add a todo', function() {
    browser.get('https://angularjs.org');

    element(by.model('todoList.todoText')).sendKeys('write first protractor test');
    element(by.css('[value="add"]')).click();

    var todoList = element.all(by.repeater('todo in todoList.todos'));
    expect(todoList.count()).toEqual(3);
    expect(todoList.get(2).getText()).toEqual('write first protractor test');

    // You wrote your first test, cross it off the list
    todoList.get(2).element(by.css('input')).click();
    var completedAmount = element.all(by.css('.done-true'));
    expect(completedAmount.count()).toEqual(2);
  });
});

Configuration ( save as conf.js)

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

To Run The Test:
Run>protractor conf.js




That’s all.





No comments:

Post a Comment