What is protractor?
Protractor is an end-to-end test framework for Angular and AngularJS applications. It runs tests against your application running in a real browser, interacting with it as a user would.
What are protractor's main functionalities?
End-to-End Testing
Protractor allows you to write end-to-end tests for your Angular applications. The code sample demonstrates navigating to an AngularJS website, selecting elements, and making assertions about their state.
const { browser, element, by } = require('protractor');
browser.get('http://www.angularjs.org');
const todoList = element.all(by.repeater('todo in todoList.todos'));
expect(todoList.count()).toEqual(2);
expect(todoList.get(1).getText()).toEqual('build an AngularJS app');
Automatic Waiting
Protractor automatically waits for Angular to finish rendering and for any outstanding $http calls to be completed before performing the next action. This reduces the need for explicit waits in your tests.
const { browser, element, by } = require('protractor');
browser.get('http://www.angularjs.org');
const addButton = element(by.css('[value="add"]'));
addButton.click();
const todoList = element.all(by.repeater('todo in todoList.todos'));
expect(todoList.count()).toEqual(3);
Integration with Jasmine
Protractor integrates seamlessly with the Jasmine testing framework, allowing you to write tests in a behavior-driven development (BDD) style. The code sample shows a Jasmine test suite that adds a new todo item and verifies its presence.
describe('angularjs homepage todo list', function() {
it('should add a todo', function() {
browser.get('http://www.angularjs.org');
element(by.model('todoList.todoText')).sendKeys('write a protractor test');
element(by.css('[value="add"]')).click();
const todoList = element.all(by.repeater('todo in todoList.todos'));
expect(todoList.count()).toEqual(3);
expect(todoList.get(2).getText()).toEqual('write a protractor test');
});
});
Other packages similar to protractor
cypress
Cypress is a next-generation front-end testing tool built for the modern web. It offers a more developer-friendly experience with features like time travel, real-time reloads, and automatic waiting. Unlike Protractor, Cypress does not require WebDriver and runs directly in the browser.
webdriverio
WebdriverIO is a popular testing framework that allows you to run tests based on the WebDriver protocol and Appium. It supports both synchronous and asynchronous commands and can be used for both web and mobile applications. WebdriverIO is more versatile compared to Protractor, which is specifically designed for Angular applications.
testcafe
TestCafe is a Node.js tool to automate end-to-end web testing. It works without WebDriver and is compatible with any modern web application. TestCafe provides a simple syntax and powerful features like parallel test execution and easy integration with CI/CD pipelines. Unlike Protractor, TestCafe is framework-agnostic and can be used with any web application.
Protractor
Protractor is an end-to-end test framework for AngularJS applications. Protractor is a Node.js program built on top of WebDriverJS. Protractor runs tests against your application running in a real browser, interacting with it as a user would.
Getting Started
The Protractor documentation for users is located in the protractor/docs folder.
To get set up and running quickly:
Once you are familiar with the tutorial, you’re ready to move on. To modify your environment, see the Protractor Setup docs. To start writing tests, see the Protractor Tests docs.
To better understand how Protractor works with the Selenium WebDriver and Selenium Server see the reference materials.
Getting Help
Check the
Protractor FAQ
and read through
the Top 20 questions on StackOverflow.
Please ask usage and debugging questions on
StackOverflow (use
the "protractor" tag)
or in the
Angular discussion group.
(Please do not ask support questions here on Github.)
For Contributors
Clone the github repository:
git clone https://github.com/angular/protractor.git
cd protractor
npm install
cd website
npm install
cd ..
Start up a selenium server. By default, the tests expect the selenium server to be running at http://localhost:4444/wd/hub
.
Protractor's test suite runs against the included test application. Start that up with
npm start
Then run the tests with
npm test
2.3.0
This release contains updates which fix some issues with dependencies that had gotten stale. However, it does not yet contain an update to the selenium-webdriver dependency, because of potential breaking changes. That update will be done in a separate Protractor@2.4.0 release. See issue 2245.
Dependency Version Upgrades
-
(cfd8d00)
feat(webdriver): update webdriver and chromedriver to latest version
Updating Selenium standalone from 2.45.0 to 2.47.0 Updating ChromeDriver from 2.15 to 2.19
Selenium Changelog:
https://github.com/SeleniumHQ/selenium/blob/master/javascript/node/selenium-webdriver/CHANGES.md
ChromeDriver Changelog: http://chromedriver.storage.googleapis.com/2.19/notes.txt
-
(802b20f)
chore(selenium): update selenium from 2.47.0 to 2.47.1
-
(7a7aca8)
chore(jasmine): bump jasmine version from 2.3.1 to 2.3.2
-
(eab828e)
chore(travis): test against node 4
Test against node 4 on Travis, and remove support for node 0.10.
-
(96def81)
chore(saucelabs): updated saucelabs dependency to 1.0.1 to support proxy
Features
-
(c989a7e)
feat(webdriver-manager): add --ie32 commandline option
The new option allows to download the 32-bit version of the IE driver on a 64-bit system, as the
64-bit version has been broken for over a year now (the sendKeys() function works very slowly on
it).
-
(ff88e96)
feat(cucumber): Allow cucumber tests containing line numbers
example:
specs: [
'cucumber/lib.feature:7'
]
Bug Fixes
-
(1487e5a)
fix(protractor.wrapDriver): allow browser instances to work even if they were not set up through
the runner
Fixes #2456
-
(2ff7a07)
fix(Chrome Accessibility Plugin): resolving the location of AUDIT_FILE
-
(f9b0a92)
fix(debugger): Fix potential debugger lockups