Protractor - End-To-End Testing For Angularjs
Protractor - End-To-End Testing For Angularjs
Protractor - End-To-End Testing For Angularjs
View on GitHub
Follow @ProtractorTest
Protractor is an end-to-end test framework for Angular and AngularJS applications. Protractor runs
tests against your application running in a real browser, interacting with it as a user would.
Setup
Use npm to install Protractor globally with:
This will install two command line tools, protractor and webdriver‐manager . Try running protractor ‐‐version to make sure it's working.
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
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 test
Open a new command line or terminal window and create a clean folder for testing.
Protractor needs two files to run, a spec file and a configuration file.
Let's start with a simple test that navigates to the todo list example in the AngularJS website and adds a new todo item to the list.
The describe and it syntax is from the Jasmine framework. browser is a global created by Protractor, which is used for browser-level commands
such as navigation with browser.get .
Configuration
Now create the configuration file. Copy the following into conf.js :
exports.config = {
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['todo‐spec.js']
};
This configuration tells Protractor where your test files ( specs ) are, and where to talk to your Selenium Server ( seleniumAddress ). It will use the
defaults for all other configuration. Chrome is the default browser.
Run the test
Now run the test with:
protractor conf.js
You should see a Chrome browser window open up and navigate to the todo list in the AngularJS page, then close itself (this should be very fast!).
The test output should be 1 test, 3 assertions, 0 failures . Congratulations, you've run your first Protractor test!
Learn More
Learn more with the Tutorial.