Open ltfschoen opened 10 years ago
I overcame the warning mentioned earlier (Warning: Task "protractor:run") by registering a 'protractor:run' task, as shown below, but it still does not execute 'protractor protractor.conf.js' when I run 'grunt test' at the command-line.
grunt.registerTask('protractor:run', function () {
var run = {
files: ['protractor.conf.js'],
tasks: ['protractor protractor:run']
};
grunt.config.set('protractor', run);
return grunt.task.run(['protractor']);
});
Also, as I do not have complex tests at this stage, I updated my 'protractor.conf.js' file to start selenium in standalone mode (i.e. so i don't have to run 'webdriver-manager start' in a separate terminal window first before running 'protractor protractor.conf.js'). Additionally, I added the multi capability so it simulates the feature tests in both Chrome and Firefox (however I get errors with Firefox). I ran the following two commands in terminal first:
npm install --save-dev protractor
npm install --save-dev chromedriver
exports.config = {
chromeOnly: true,
chromeDriver: './node_modules/chromedriver/bin/chromedriver',
multiCapabilities:
[{
'browserName': 'chrome',
'chromeOptions': {
args: ['--test-type']
}
},
{
'browserName': 'firefox'
}
],
onPrepare: function() {
browser.driver.manage().window().setSize(800, 600);
},
specs: ['./test/e2e/*_test.js'],
baseUrl: 'http://localhost:9000', //default test port with Yeoman is 127.0.0.1 (localhost)
jasmineNodeOpts: {
showColors: true,
isVerbose: true,
includeStackTrace: true
}
};
@ltfschoen First off, great job. I am glad someone is working on a PR for this.
I have E2E/protractor tests implemented and I started off using this generator for my project so I am happy to give some input on this if it helps get that back into the original generator. My configs are weird because we use Saucelabs to run our tests on our CI server, but give devs the ability to run the tests locally if they prefer. At first I tried something like your method, using protractor directly, but then later decided to use https://github.com/teerapap/grunt-protractor-runner which some of the heavy lifting for you.
I ended up with two separate commands that I call depending on which testing environment I want to run my tests in. There certainly might be a better way to do this, but currently I haven't had a chance to investigate further.
Run e2e tests at saucelabs
grunt protractor:sauce
Run e2e tests locally
grunt protractor:local
To get it working, I had to make the following changes to my Gruntfile.js:
Inside of grunt.initConfig({ ... here.... });
i inserted:
protractor: {
options: {
configFile: 'node_modules/protractor/referenceConf.js', // Default config file
keepAlive: false, // If false, the grunt process stops when the test fails.
noColor: false, // If true, protractor will not use colors in its output.
verbose: true,
args: {
// Arguments passed to the command
}
},
sauce: {
options: {
verbose:true,
keepAlive: false,
configFile: 'protractor.sauce.conf.js',
args: {}
}
},
local: {
options: {
verbose: true,
keepAlive:false,
configFile: 'protractor.local.conf.js',
args: {}
}
}
}
At the end of my Gruntfile.js:
grunt.loadNpmTasks('grunt-protractor-runner');
protractor.local.conf.js looks like this:
/* The local protractor config */
exports.config = {
baseUrl: 'http://localhost:9000/index.html',
multiCapabilities: [
{
'browserName': 'safari'
}, {
'browserName': 'chrome'
}
// Commented out until protractor upgrades to webdriver v2.43
// which supports Firefox 32
//, {
// 'browserName': 'firefox'
// }
],
specs: ['test/spec/e2e/**/*.js'],
framework: 'jasmine',
jasmineNodeOpts: {
showColors: true
}
};
My saucelabs bamboo config looks like this:
var path = require('path');
/* Transform the bambo sauce environment variable into a protractor variable */
var browsersTransformed = [];
var browsersFromEnvironment = JSON.parse(process.env.bamboo_SAUCE_ONDEMAND_BROWSERS);
browsersFromEnvironment.forEach(function(browser){
browsersTransformed.push({
'browserName': browser.browser,
'name': 'Mobile E2E',
'build': process.env.BAMBOO_BUILDNUMBER
});
});
/* The protractor config */
exports.config = {
seleniumPort: process.env.SELENIUM_PORT,
baseUrl: 'http://localhost:9000/index.html',
multiCapabilities: browsersTransformed,
sauceUser: process.env.SAUCE_USER_NAME,
sauceKey: process.env.SAUCE_API_KEY,
specs: ['test/spec/e2e/**/*.js'],
framework: 'jasmine',
jasmineNodeOpts: {
showColors: false
}
};
Obviously to use grunt-protractor-runner you will need to add it via npm as well. One thing about going this route is that you should make sure to do is to ensure that you run node_modules/grunt-protractor-runner/scripts/webdriver-manager-update
to make sure you are using the local version of webdriver inside the project instead of relying on a globally installed version.
@jimthedev Thanks Jim for sharing some great tips, I'll be sure to test them out!
@jimthedev Awesome that you got Protractor running on SauceLabs with Bamboo integration. Exactly such a recipe I have been looking for all day. Any chance you could write a blog post on how this setup works in more detail? Which resources did you use to piece this together? How do I integrate the Bamboo and/or Sauce test reports with JIRA or similar external tools? Cheers!
@kristianmandrup I think that would be possible but it might be a couple weeks. I've got some hard deadlines the next two weeks, so if you have pressing questions I can answer them in brief or you can wait. Whatever you prefer.
Thanks ;) No rush. In a few weeks would be excellent. We will see how far we can get from tips you have provided so far...
Progress
@diegonetto I want to create a pull request and update the Readme section on E2E Tests using Protractor. With the way I have set it up on the latest commit on my custom Generate Ionic app so far I have managed to get Protractor to work but only manually with the following command (and it performs similar to Capybara with Selenium Web Server in Rails with the feature tests automatically opening my browser, and entering inputs into form fields that I have predefined):
I have attempted to register the task in the Gruntfile.js (by adding an additional line "protractor:run" under "grunt.registerTask('test'...") but when I do and run the following command it just stops and doesn't run properly:
Setup Methodology for Manual Protractor Testing
Setup Methodology for Automated Protractor Testing
Any ideas?
My system info
i get the following info about my ChromeDriver version when i run the command 'webdriver-manager start'