是的,这是可能的。
- 第一种方式:(仅适用于使用简单命令“protractor [config file]”从控制台运行它
只需使用 NPM 运行一次命令:
npm install protractor@2.5.1
npm install selenium-standalone-jar@2.45.0
这将安装所需的软件包。
接下来修改protractor.conf.js,用selenium Standalone代替selenium地址:
//seleniumAddress: 'http://localhost:4444/wd/hub',
seleniumServerJar: './node_modules/selenium-standalone-jar/bin/selenium-server-standalone-2.45.0.jar',
现在,当你运行 protractor [配置文件] 时,例如:protractor protractor.conf.js,他将为自己启动 selenium 并进行测试。
- 第二种方式:
您可以在构建过程中实现它,在使用 GULP 构建期间,他会为您启动量角器,而量角器将自己启动 selenium-driver。
我看到你运行这些命令真的很累,你为什么还要这样做,只是使用 Gulp 为你做。
我将在工作示例中向您解释这一点。
你只需要:
添加到您的 (NPM) package.json 文件中:(选择适合您的版本,这对我有用。
"gulp-protractor": "^2.1.0",
"protractor": "2.5.1",
"selenium-standalone-jar": "2.45.0",
然后你需要在 protractor.conf.js 中进行正确的配置:
您需要用直接 JAR 文件替换“seleniumAddress”,以便量角器为您触发并自动附加到它!
一段文件是:
framework: 'jasmine',
//seleniumAddress: 'http://localhost:4444/wd/hub',
seleniumServerJar: './node_modules/selenium-standalone-jar/bin/selenium-server-standalone-2.45.0.jar',
seleniumServerJar 是文件的参考路径,该文件将与您的 package.json 文件中的 "selenium-standalone-jar": "2.45.0" 一起安装。
最后一步是正确地完成一个 gulp 任务,这是我的:
var angularProtractor = require('gulp-angular-protractor');
gulp.task('protractor-test', function(callback) {
gulp
.src(['./**/*.js']) -<
.pipe(angularProtractor({
'configFile': 'protractor.conf.js',
'debug': true,
'autoStartStopServer': true
}))
.on('error', function(e) {
console.log(e);
})
.on('end', callback);
});
享受吧!