>我使用量角器 v1.4.0,我想从命令行设置量角器 baseUrl,所以我不能使用
baseUrl: 'http://localhost:8000/',
量角器配置文件中的配置选项。我想在量角器配置文件中使用"参数"选项定义基本 url 的默认值,如下所示:
params: {
baseUrl: 'http://localhost:8080/'
},
然后在我运行量角器时通过从命令行传递一个新值来覆盖默认值,如下所示:
protractor 'path_to_my_conf_file' --params.baseUrl http://localhost:80/
然后在我的规范文件中,我需要使用量角器 API 设置基本 URL,但我找不到如何做到这一点。
以下问题的第一个答案正是我所需要的,但它不起作用。
如何将 URL 动态添加到量角器测试中?
作为另一种选择,也可以尝试在onPrepare
中browser.baseUrl = "https://test-url.com"
(适用于量角器 1.4.0)
你可以从命令行更改它,如下所示:
protractor --baseUrl http://whateveryouwant
通过grunt
运行带有grunt-protractor-runner
和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
使用 gulp 进行测试运行;如下所示是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