2014-12-03 39 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 
相關問題