2014-12-03 78 views
5

我用量角器V1.4.0,我想从命令行设置量角器的baseUrl,所以我不能使用量角器配置文件如何使用量角器API而不是配置文件来设置量角器(v1.4.0)baseUrl?

baseUrl: 'http://localhost:8000/',

配置选项。我要定义基本的URL默认值与“PARAMS”选项量角器配置文件如下:

params: { baseUrl: 'http://localhost:8080/' },

,然后通过命令行传递一个新值覆盖默认值当我运行量角器如下:

protractor 'path_to_my_conf_file' --params.baseUrl http://localhost:80/

然后在我的规范文件,我需要用量角器API设置基本的URL,但我无法找到如何做到这一点。

以下问题的第一个答案正是我需要的,但它不起作用。与grunt-protractor-runner通过grunt

How can I add URL's dynamically to Protractor tests?

回答

4

你可以只改变它的命令行,像这样:

protractor --baseUrl http://whateveryouwant 
2

运行测试和grunt-option库:

protractor: { 
    options: { 
     configFile: "path_to_my_conf_file", 
     args: { 
      baseUrl: grunt.option('baseUrl', 'http://localhost:80/') 
     } 
    } 
} 

然后,通过运行任务:

grunt protractor --baseUrl=http://mynewurl 

而且,让它使用默认baseUrl,只需运行:

grunt protractor 
+0

我想这样做,没有呻吟,我认为应该有一种方法来设置的baseUrl只是量角器API。 – 2014-12-03 18:34:19

+0

@SurenAznauryan和'量角器--baseUrl = http:// mynewurl'不适合你,对不对? – alecxe 2014-12-03 19:35:08

+0

没有尝试过,它应该工作吗? – 2014-12-03 20:00:09

6

作为另一种选择,也可以尝试在browser.baseUrl = "https://test-url.com"onPrepare(工作在量角器1.4.0)为

0

使用您的一饮而尽测试运行;如下图所示是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 
); 
}); 

任务运行:

gulp test 
相关问题