5
votes

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?

4

4 Answers

7
votes

As another option, could also try browser.baseUrl = "https://test-url.com" in onPrepare (works in Protractor 1.4.0)

4
votes

You can just change it from the command line like so:

protractor --baseUrl http://whateveryouwant
2
votes

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
0
votes

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