Reputation: 206
i use protractor v1.4.0 and I want to set protractor baseUrl from command line so i can't use
baseUrl: 'http://localhost:8000/',
config option in protractor configuration file. I want to define default value for base url with "params" option in protractor configuration file as follows:
params: {
baseUrl: 'http://localhost:8080/'
},
and then overwrite the default value by passing a new value from command line when i run protractor as follows:
protractor 'path_to_my_conf_file' --params.baseUrl http://localhost:80/
then in my spec file i need to set base url using protractor API, but i can't find how to do that.
The 1-st answer to the following question is exactly what i need but it doesn't work.
How can I add URL's dynamically to Protractor tests?
Upvotes: 5
Views: 5608
Reputation: 21129
Use gulp for your test run; shown below is the gulpfile.js
var gulp = require('gulp');
var runSequence = require('run-sequence');
var protractor = require('gulp-protractor').protractor;
gulp.task('protractor', function() {
var configFile = 'test/e2e/protractor-config.js';
return gulp
.src(['./test/e2e/spec/sample.js'])
.pipe(protractor({
configFile: configFile,
args: ['--baseUrl', 'http://www.google.com']
}))
.on('error', function(e) { throw e; });
});
gulp.task('test', function(callback) {
runSequence(
'protractor',
callback
);
});
Task run:
gulp test
Upvotes: 0
Reputation: 991
As another option, could also try browser.baseUrl = "https://test-url.com"
in onPrepare
(works in Protractor 1.4.0)
Upvotes: 7
Reputation: 12108
You can just change it from the command line like so:
protractor --baseUrl http://whateveryouwant
Upvotes: 4
Reputation: 473833
Run tests via grunt
with grunt-protractor-runner
and grunt-option
libraries:
protractor: {
options: {
configFile: "path_to_my_conf_file",
args: {
baseUrl: grunt.option('baseUrl', 'http://localhost:80/')
}
}
}
Then, run the task via:
grunt protractor --baseUrl=http://mynewurl
And, to let it use the default baseUrl
, just run:
grunt protractor
Upvotes: 2