1: Install Protractor and Webdriver-Manager
Open a Node command prompt
Two tools will be installed when you run “npm install -g protractor“.
- Protractor: https://angular.github.io/protractor/#/
- Webdriver-Manager: https://www.npmjs.com/package/webdriver-manager
Test your install by running “protractor –version”
2: Update Webdriver-Manager
Next, download some needed binaries with “webdriver-manager update”
3: Start the server
Start the server with “webdriver-manager start“.
What you should have now is a running instance of Selenium. Protractor tests send their requests to this server which controls the local browser. Status information should be visible here: http://localhost:4444/wd/hub
4: Create a simple test
This will require two files. One with some basic configuration information “conf.js” and another with a simple test “todo-spec.js”. Put the following in each respective file.
conf.js
exports.config = {
seleniumAddress: ‘http://localhost:4444/wd/hub’,
specs: [‘todo-spec.js’]
};
todo-spec.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);
});
});
To run the test, from the Node command prompt, cd into the folder where you have saved the two files and execute the following “protractor conf.js“.