Protractor is an end to end test framework for AngularJS applications built on top of WebDriverJS.
Protractor can be run as a standalone binary runner, 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 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, but other adapters may be added in the future.
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
andsauceKey
: 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
< 5FF3 div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="protractor myConf.js">protractor myConf.js