I'm currently playing around with E2E tests an Protractor in my AngularJS app and Grunt. I followed the installation from https://www.npmjs.org/package/grunt-protractor-runner, and I have 2 questions:
First:
I was wondering, if it's possible, to have that behaviour from my unit tests with Karma:
- start the test server
- run all tests
- when a test file or any other html/js file changes, re-run all tests
I like that way with live watch and auto reloading very much, because it reduces the startup time from the whole suite, and makes everything faster.
But with Protractor, I have a problem: Everytime I start the test with Grunt, the tests are executed, and then everything shuts down. Although, I set the keepAlive
option to true
in the protractor configuration part of my Gruntfile.js
. Any ideas?
Second:
I can't get it to work, to connect Protractor to my angular app. Do I have to start the grunt server, to serve the files? When I try to visit a page in my tests like browser.get('app/index.html');
or browser.get('#/');
, I can't access the page. I've played around with the baseUrl
option (like baseUrl: 'http://localhost:' + (process.env.HTTP_PORT || '8000')
) from my protractor.conf.js
. But to me it looks like, I have to start the grunt server before, am I right? And how can I do this? Or are there any other options for accessing my angular app? I'm using sass with compass, so I think, I need the compass:dist
taks in some way.
UPDATE:
I found a workaround. I registered the following grunt task:
grunt.registerTask('e2e', [
'clean:server',
'concurrent:test',
'autoprefixer',
'connect:test',
'concurrent:server',
'autoprefixer',
'protractor',
'watch'
]);
When started with grunt e2e
my server gets started, based on the baseUrl: 'http://10.0.0.200:9001'
inside my protractor.conf.js
, and my tests are running. When the tests are completed, the watch
task watches for changed files, and reruns protractor if needed.
The drawback of this is, that everytime watch
starts the protractor
task, a new Chrome instance is spawned, and after the test killed. Is there a way to prevent protractor from killing the Chrome instance?
Furthermore, I was wondering why in every tutorial it always says sth like "Just run grunt protractor
and your tests are executed...". Why do I need an additional task for starting up my grunt server to access my angularjs application?
And here are my config files:
protractor.conf.js
exports.config = {
capabilities: {
'browserName': 'chrome'
},
chromeOnly: true,
specs: ['test/e2e/**/*.js'],
jasmineNodeOpts: {
showColors: true
},
framework: 'jasmine'
};
Gruntfile.js
module.exports = function(grunt) {
// Load grunt tasks automatically
require('load-grunt-tasks')(grunt);
grunt.loadNpmTasks('grunt-protractor-runner');
grunt.initConfig({
// ...
protractor: {
options: {
configFile: "protractor.conf.js",
keepAlive: false,
noColor: false
},
run: {}
},
// ...
});
// ...
grunt.registerTask('test:e2e', [
'clean:server',
'compass:dist',
'compass:server',
'autoprefixer',
'connect:test',
'protractor'
]);
// ...
}
thanks!