Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
protractor
Advanced tools
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.
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');
});
});
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 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 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 is an end to end test framework for AngularJS applications built on top of WebDriverJS. Protractor runs tests against your application running in a real browser, interacting with it as a user would.
Protractor can be run as a standalone binary, or included into your tests as a library. Use Protractor as a library if you would like to manage WebDriver and your test setup yourself.
For more information, read the docs, or head over to the FAQ.
Install protractor with.
npm install -g protractor
Start up a selenium server (See the appendix below for help with this). By default, the tests expect the selenium server to be running at http://localhost:4444/wd/hub
.
The node module's example folder contains a simple test suite which runs against angularjs.org. Run with:
protractor example/conf.js
The Protractor runner is a binary which accepts a config file. Install protractor with
npm install -g protractor
# Run the line below to see command line options
protractor
You will need a configuration file containing setup info and test files containing the actual test scripts. The config file specifies how the runner should start webdriver, where your test files are, and global setup options. The test files use Jasmine framework by default (read about using mocha instead).
Create a configuration file - an example with detailed comments is shown in node_modules/protractor/referenceConf.js
. Edit the configuration file to point to your test files.
// myConf.js
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['myTest.js', 'myTestFolder/*Test.js']
}
The configuration file must specify a way to connection to webdriver. This can be
seleniumAddress
: The address of a running selenium standalone server.seleniumServerJar
: The location of the selenium standalone .jar file on your machine. Protractor will use this to start up the selenium server.sauceUser
and sauceKey
: The username and key for a SauceLabs account. Protractor will use this to run tests on SauceLabs.The runner exposes global variables browser
, by
and element
. Check out getting started docs to learn how to write a test.
// myTest.js
describe('angularjs 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!');
});
});
Run with
protractor myConf.js
Clone the github repository.
git clone https://github.com/angular/protractor.git
cd protractor
npm install
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 testapp. Start that up with
cd testapp
./scripts/web-server.js
Then run the tests with
npm test
WebdriverJS does not natively include the selenium server - you must start a standalone selenium server. All you need is the latest selenium-server-standalone.. To drive individual browsers, you may need to install separate driver binaries.
To use with chrome browsers, download chromedriver. More information about chromedriver
The webdriver-manager
script is included in the npm package to manage downloads for you. To see the options, run
npm install -g protractor
webdriver-manager
Download and start the selenium server with
webdriver-manager update
webdriver-manager start
Note the Java Development Kit (JDK) is also required to run the webdriver. You may have to download and install it if your computer does not already have it.
For alternate ways to download and start the selenium standalone, see the webdriver docs.
0.20.0
Note: Major version 0 releases are for initial development, and backwards incompatible changes may be introduced at any time.
(220d793), (6603a7e) chore(webdriver): update selenium version to 2.40.0 and download location
(ad5f3aa) feat(jasminewd): allow custom matchers to return promises
Allow custom jasmine matchers to return a promise which resolves to a boolean and match against the resolution of the promise
(41feaca) feat(framework.cucumber): Allow multiple tags on cucumber tests.
Motivation: Support for multiple tags on the cucumber test execution, to be able to filter with more complex expressions the scenarios to run.
How to use:
cucumberOpts: {
tags: '@dev'
}
or
cucumberOpts: {
tags: ['@dev', '~@ignore']
}
More information on tags: https://github.com/cucumber/cucumber/wiki/Tags
(2ca6541) fix(debug): make protractor debug work in the new runner/launcher world
Closes #552
(a68627b) fix(launcher): command line args should be passed as-is to the runner
This allows users to continue to use optimist (or other process.argv) processing within their tests and grab values from the command line.
Closes #571.
(767c306), (02defe3) fix(jasminewd): include full pre-async-call stack trace in expectation failure message
(b6df2cf) fix(configParser): load coffee and LiveScript for child processes
Without loading coffee in configParser.js, child processes which try and load a coffeescript config file do not have coffee registered with node's required, and child tests fail.
Fixes an issue with using coffeescript config files.
(64bee25) fix(locators): add locator with multiple arguments
When using a custom locator with multiple arguments, only the first argument was used when
calling webdriver.findElements
.
(87b0c7f) fix(debug): display error message when runner fails
FAQs
Webdriver E2E test wrapper for Angular.
We found that protractor demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.