Top Related Projects
Fast, easy and reliable testing for anything that runs in a browser.
JavaScript API for Chrome and Firefox
Next-gen browser and mobile automation test framework for Node.js
A browser automation framework and ecosystem.
Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack
Quick Overview
Protractor is an end-to-end testing framework for Angular and AngularJS applications. It runs tests against your application running in a real browser, interacting with it as a user would.
Pros
- Specifically designed for Angular applications, providing seamless integration
- Supports automatic waiting and synchronization with Angular
- Offers a wide range of locator strategies for finding elements
- Integrates well with Selenium WebDriver for browser automation
Cons
- Learning curve can be steep for beginners
- Performance can be slow for large test suites
- Limited support for non-Angular applications
- Maintenance has been discontinued, with Angular recommending alternatives
Code Examples
- Basic element interaction:
describe('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');
});
});
- Using async/await:
describe('angular homepage', function() {
it('should greet the named user', async function() {
await browser.get('https://angularjs.org');
await element(by.model('yourName')).sendKeys('Julie');
var greeting = element(by.binding('yourName'));
expect(await greeting.getText()).toEqual('Hello Julie!');
});
});
- Custom locator:
by.addLocator('buttonText', function(buttonText, opt_parentElement) {
var using = opt_parentElement || document;
var buttons = using.querySelectorAll('button');
return Array.prototype.filter.call(buttons, function(button) {
return button.textContent === buttonText;
});
});
element(by.buttonText('Save')).click();
Getting Started
-
Install Protractor globally:
npm install -g protractor
-
Update webdriver-manager:
webdriver-manager update
-
Create a configuration file (conf.js):
exports.config = { framework: 'jasmine', seleniumAddress: 'http://localhost:4444/wd/hub', specs: ['spec.js'] };
-
Write your first test (spec.js):
describe('Protractor Demo App', function() { it('should have a title', function() { browser.get('http://juliemr.github.io/protractor-demo/'); expect(browser.getTitle()).toEqual('Super Calculator'); }); });
-
Run the test:
protractor conf.js
Competitor Comparisons
Fast, easy and reliable testing for anything that runs in a browser.
Pros of Cypress
- Faster test execution and setup due to running directly in the browser
- More intuitive debugging with time-travel and real-time reloads
- Better handling of asynchronous operations without explicit waits
Cons of Cypress
- Limited cross-browser testing capabilities (primarily supports Chrome)
- Lack of native mobile testing support
- Steeper learning curve for developers familiar with Selenium-based tools
Code Comparison
Protractor (JavaScript):
describe('Protractor Demo', function() {
it('should have a title', function() {
browser.get('http://juliemr.github.io/protractor-demo/');
expect(browser.getTitle()).toEqual('Super Calculator');
});
});
Cypress (JavaScript):
describe('Cypress Demo', () => {
it('should have a title', () => {
cy.visit('http://juliemr.github.io/protractor-demo/');
cy.title().should('eq', 'Super Calculator');
});
});
Summary
Cypress offers a more modern and developer-friendly approach to end-to-end testing, with faster execution and improved debugging capabilities. However, it has limitations in cross-browser and mobile testing. Protractor, being Selenium-based, provides broader browser support but may require more setup and explicit handling of asynchronous operations. The choice between the two depends on specific project requirements and team preferences.
JavaScript API for Chrome and Firefox
Pros of Puppeteer
- Supports both Chrome and Firefox browsers
- Offers more control over browser automation and page interactions
- Actively maintained and widely adopted in the industry
Cons of Puppeteer
- Steeper learning curve for those familiar with Protractor's syntax
- Requires more setup and configuration for testing Angular applications
- May need additional libraries for certain testing scenarios
Code Comparison
Protractor example:
describe('Angular homepage', function() {
it('should greet the named user', function() {
browser.get('http://www.angularjs.org');
element(by.model('yourName')).sendKeys('Julie');
var greeting = element(by.binding('yourName'));
expect(greeting.getText()).toEqual('Hello Julie!');
});
});
Puppeteer example:
describe('Angular homepage', () => {
it('should greet the named user', async () => {
await page.goto('http://www.angularjs.org');
await page.type('input[ng-model="yourName"]', 'Julie');
const greeting = await page.$eval('.greeting', el => el.textContent);
expect(greeting).toBe('Hello Julie!');
});
});
Both Protractor and Puppeteer are powerful tools for web testing and automation. Protractor is specifically designed for Angular applications, while Puppeteer offers more flexibility for various web technologies. The choice between them depends on the project requirements, team expertise, and long-term maintenance considerations.
Next-gen browser and mobile automation test framework for Node.js
Pros of WebdriverIO
- More versatile, supporting various frameworks and browsers beyond Angular
- Active development and frequent updates
- Extensive plugin ecosystem for enhanced functionality
Cons of WebdriverIO
- Steeper learning curve for beginners
- Configuration can be more complex
- May require additional setup for certain integrations
Code Comparison
WebdriverIO:
describe('My Login application', () => {
it('should login with valid credentials', async () => {
await browser.url('https://example.com/login');
await $('#username').setValue('myuser');
await $('#password').setValue('mypassword');
await $('button[type="submit"]').click();
await expect($('#logged-in-message')).toBeExisting();
});
});
Protractor:
describe('Login application', function() {
it('should login with valid credentials', function() {
browser.get('https://example.com/login');
element(by.id('username')).sendKeys('myuser');
element(by.id('password')).sendKeys('mypassword');
element(by.css('button[type="submit"]')).click();
expect(element(by.id('logged-in-message')).isPresent()).toBeTruthy();
});
});
Both frameworks offer similar functionality for web testing, but WebdriverIO provides a more modern syntax and broader application beyond Angular-specific projects. Protractor, while tailored for Angular, has a simpler setup process and may be easier for Angular developers to adopt initially.
A browser automation framework and ecosystem.
Pros of Selenium
- Supports multiple programming languages (Java, Python, C#, Ruby, etc.)
- Works with various browsers (Chrome, Firefox, Safari, Edge)
- Larger community and more extensive documentation
Cons of Selenium
- Steeper learning curve for beginners
- Requires more setup and configuration
- Can be slower for large test suites compared to Protractor
Code Comparison
Selenium (Java):
WebDriver driver = new ChromeDriver();
driver.get("https://www.example.com");
WebElement element = driver.findElement(By.id("submit-button"));
element.click();
Assert.assertTrue(driver.getTitle().contains("Success"));
Protractor (JavaScript):
browser.get('https://www.example.com');
let element = element(by.id('submit-button'));
element.click();
expect(browser.getTitle()).toContain('Success');
Both Selenium and Protractor are popular tools for automated testing of web applications. Selenium is a more versatile option with support for multiple languages and browsers, making it suitable for a wide range of projects. However, it can be more complex to set up and use, especially for beginners.
Protractor, on the other hand, is specifically designed for Angular applications and offers a more streamlined experience for testing Angular-based projects. It has a simpler syntax and is generally easier to learn for those familiar with JavaScript and Angular development.
The choice between Selenium and Protractor often depends on the specific requirements of the project, the development team's expertise, and the target application's technology stack.
Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
Pros of Playwright
- Cross-browser support for Chromium, Firefox, and WebKit
- Auto-wait functionality for improved test stability
- Powerful API for modern web app testing
Cons of Playwright
- Steeper learning curve for developers new to end-to-end testing
- Requires more setup and configuration compared to Protractor
Code Comparison
Playwright:
const { chromium } = require('playwright');
(async () => {
const browser = await chromium.launch();
const page = await browser.newPage();
await page.goto('https://example.com');
await browser.close();
})();
Protractor:
describe('Protractor Demo', function() {
it('should have a title', function() {
browser.get('https://example.com');
expect(browser.getTitle()).toEqual('Example Domain');
});
});
Key Differences
- Playwright supports multiple browsers natively, while Protractor is primarily designed for Angular applications
- Playwright uses a more modern async/await syntax, whereas Protractor relies on promise-based syntax
- Playwright offers better performance and stability for complex web applications
Conclusion
While Protractor has been a popular choice for Angular applications, Playwright provides a more versatile and powerful solution for modern web testing across multiple browsers and frameworks.
Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack
Pros of Nightwatch
- Supports multiple browsers and testing environments out of the box
- Built-in test runner and assertion library for easier setup
- Active development and community support
Cons of Nightwatch
- Steeper learning curve for beginners
- Less integration with Angular-specific features
- Requires more configuration for complex scenarios
Code Comparison
Protractor (Angular-specific):
describe('Angular App', function() {
it('should have a title', function() {
browser.get('http://localhost:4200');
expect(browser.getTitle()).toEqual('My Angular App');
});
});
Nightwatch (More general-purpose):
module.exports = {
'Demo test' : function (browser) {
browser
.url('http://localhost:4200')
.assert.titleContains('My Angular App')
.end();
}
};
Key Differences
- Protractor is specifically designed for Angular applications, while Nightwatch is more versatile for various web applications.
- Protractor uses Jasmine for test structure, while Nightwatch has its own test syntax.
- Nightwatch offers built-in reporting and parallel test execution, which Protractor requires additional setup for.
Conclusion
Choose Protractor for Angular-specific projects with seamless integration, or opt for Nightwatch for more flexibility across different web technologies and testing environments.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
Protractor
Protractor is an end-to-end test framework for Angular and 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.
Compatibility
Protractor 5 is compatible with nodejs v6 and newer.
Protractor works with AngularJS versions greater than 1.0.6/1.1.4, and is compatible with Angular applications. Note that for Angular apps, the binding
and model
locators are not supported. We recommend using by.css
.
Getting Started
See the Protractor Website for most documentation.
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), the Gitter chat room, or in the Angular discussion group. (Please do not ask support questions here on Github.)
For Contributors
See DEVELOPER.md
Top Related Projects
Fast, easy and reliable testing for anything that runs in a browser.
JavaScript API for Chrome and Firefox
Next-gen browser and mobile automation test framework for Node.js
A browser automation framework and ecosystem.
Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
Integrated end-to-end testing framework written in Node.js and using W3C Webdriver API. Developed at @browserstack
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot