-
Install
protractorandgrunt-protractor-runnerfromnpm:npm install protractor grunt-protractor-runner --save-dev -
Create a config file for protractor (
protractor.conf.js), changespecsandbaseUrlto your test files and test server:exports.config = { seleniumAddress: 'http://localhost:4444/wd/hub', specs: ['test/e2e/*_test.js'], baseUrl: 'http://localhost:9001' //default test port with Yeoman } -
Update your
Gruntfile.js, add the following after the karma task:protractor: { options: { keepAlive: true, configFile: "protractor.conf.js" }, run: {} } -
Add the protractor task under test
grunt.registerTask('test', [ 'clean:server', 'concurrent:test', 'autoprefixer', 'connect:test', 'karma', 'protractor:run' ]); -
Download and start the selenium server:
node_modules/protractor/bin/webdriver-manager update node_modules/protractor/bin/webdriver-manager start(In Windows:)
node node_modules/protractor/bin/webdriver-manager update node node_modules/protractor/bin/webdriver-manager start -
Update your
package.json, add the following after"devDependencies". This will run the command afternpm installso you don’t need to remember every time."scripts": { "install": "node node_modules/protractor/bin/webdriver-manager update" } -
Run the test using grunt
grunt test
If you want protractor to start the server for you, remove
seleniumAddress: 'http://localhost:4444/wd/hub',
from protractor.conf.js, then running grunt test will start a standalone selenium instance during the test and quit it after running the test suite.