Is there a way to run e2e tests using Protractor and Gulp in a single task?
有没有办法在单个任务中使用Protractor和Gulp运行e2e测试?
Right now, in order to run e2e tests, I have to open 3 separate shells and run the following:
现在,为了运行e2e测试,我必须打开3个单独的shell并运行以下命令:
webdriver-manager update
webdriver-manager start
npm start (which runs the app server)
protractor protractor.conf.js (in a separate window)
There must be a simpler way of running these tests. Any thoughts?
必须有一种更简单的方法来运行这些测试。有什么想法吗?
4 个解决方案
#1
8
Here is a solution that can work
这是一个可行的解决方案
var protractor = require("gulp-protractor").protractor;
var spawn = require('child_process').spawn;
//run webdriver method
function runWebdriver(callback) {
spawn('webdriver-manager', ['start'], {
stdio: 'inherit'
}).once('close', callback);
}
//run protractor.config method
function runProtractorConfig() {
gulp.src('./**/*-page.spec.js')
.pipe(protractor({
configFile: 'protractor.config.js'
}))
.on('error', function (e) {
throw e;
});
}
//execute protractor.config after webdriver is executed
function runWebdriverProtractor(){
runWebdriver(runProtractorConfig);
}
//put them into gulp task
gulp.task('run-protractor', runWebdriverProtractor);
#2
3
Yes it's possible.
是的,这是可能的。
- First way: (only for running it from console with simple command " protractor [config file] "
- 第一种方式:(仅用于通过简单命令“protractor [config file]”从控制台运行它
Just run once command with NPM:
用NPM运行一次命令:
npm install protractor@2.5.1
npm install selenium-standalone-jar@2.45.0
This will install required packages.
这将安装所需的包。
Next modify the protractor.conf.js with selenium standalone instead of selenium address:
接下来用selenium standalone而不是selenium地址修改protractor.conf.js:
//seleniumAddress: 'http://localhost:4444/wd/hub',
seleniumServerJar: './node_modules/selenium-standalone-jar/bin/selenium-server-standalone-2.45.0.jar',
Now when you run protractor [ config file] like: protractor protractor.conf.js he will start selenium for himself and make tests.
现在当你运行量角器[配置文件]时:protractor protractor.conf.js他将为自己启动selenium并进行测试。
- Second way:
- 第二种方式:
You can implement that into build process, during build with GULP he will fire for you protractor and protractor will fire up selenium-driver himself.
您可以将其实施到构建过程中,在使用GULP构建期间,他将为您开发量角器,量角器将自己启动硒驱动器。
I see that its really tiring to you to run those command, why would you do that even, just use Gulp to make it for you.
我看到你运行这些命令真的很累,为什么你会这样做,只需用Gulp为你做。
I will explain you this on working example.
我将以工作实例向您解释这一点。
All you need is:
所有你需要的是:
Add to your (NPM) package.json file: (pick the version that suits you, this works for me.
添加到您的(NPM)package.json文件:(选择适合您的版本,这对我有用。
"gulp-protractor": "^2.1.0",
"protractor": "2.5.1",
"selenium-standalone-jar": "2.45.0",
Then you need the proper config in protractor.conf.js: You need to replace the "seleniumAddress" with direct JAR file so the protractor will fire it for you and attach to it automaticly! piece of file is:
然后你需要在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',
The seleniumServerJar is a reference path to the file which will be installed with "selenium-standalone-jar": "2.45.0", from your package.json file.
seleniumServerJar是该文件的引用路径,该文件将与package.json文件中的“selenium-standalone-jar”:“2.45.0”一起安装。
And last step is to properly make a gulp task, here's mine:
最后一步是正确地完成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);
});
Enjoy!
请享用!
#3
2
You can run testsuite as well by just adding --suite in 'args'.
您也可以通过在'args'中添加--suite来运行测试套件。
var angularProtractor = require('gulp-angular-protractor');
gulp.task('test', function (callback) {
gulp
.src([__dirname+'/public/apps/adminapp/**/**_test.js'])
.pipe(angularProtractor({
'configFile': 'public/apps/adminapp/app.test.config.js',
'debug': false,
'args': ['--suite', 'adminapp'],
'autoStartStopServer': true
}))
.on('error', function(e) {
console.log(e);
})
.on('end',callback);
});
#4
0
A complete solution, (working with Travis CI)
-
npm
configuration - npm配置
Basically, configure http-server
to start before you run gulp script. Later on you will have to run the tests via npm
, fe. npm test
or npm run <action>
if you choose other name.
基本上,配置http-server以在运行gulp脚本之前启动。稍后您必须通过npm,fe运行测试。 npm test或npm run
"devDependencies": {
"gulp-angular-protractor": "latest",
"http-server": "^0.9.0",
...
},
"scripts": {
"pretest": "npm install",
"test": "(npm start > /dev/null &) && (gulp protractor)",
"start": "http-server -a localhost -p 8000 -c-1 ./",
"dev": "(npm start > /dev/null &) && (gulp dev)"
},
- setup
gulp
withgulp-angular-protractor
- 用gulp-angular-protractor设置gulp
Define the action you want to run.
定义要运行的操作。
var gulpProtractorAngular = require('gulp-angular-protractor');
...
gulp.task('protractor', function (callback) {
gulp
.src('tests/*.js')
.pipe(gulpProtractorAngular({
'configFile': 'protractor.conf.js',
'debug': false,
'autoStartStopServer': true,
'verbose': false,
'webDriverUpdate': {
'browsers': ['ie', 'chrome']
}
}))
.on('error', function (e) {
console.log(e);
})
.on('end', callback);
});
See the above in action in GitHub project: https://github.com/atais/angular-eonasdan-datetimepicker
请参阅GitHub项目中的上述操作:https://github.com/atais/angular-eonasdan-datetimepicker
#1
8
Here is a solution that can work
这是一个可行的解决方案
var protractor = require("gulp-protractor").protractor;
var spawn = require('child_process').spawn;
//run webdriver method
function runWebdriver(callback) {
spawn('webdriver-manager', ['start'], {
stdio: 'inherit'
}).once('close', callback);
}
//run protractor.config method
function runProtractorConfig() {
gulp.src('./**/*-page.spec.js')
.pipe(protractor({
configFile: 'protractor.config.js'
}))
.on('error', function (e) {
throw e;
});
}
//execute protractor.config after webdriver is executed
function runWebdriverProtractor(){
runWebdriver(runProtractorConfig);
}
//put them into gulp task
gulp.task('run-protractor', runWebdriverProtractor);
#2
3
Yes it's possible.
是的,这是可能的。
- First way: (only for running it from console with simple command " protractor [config file] "
- 第一种方式:(仅用于通过简单命令“protractor [config file]”从控制台运行它
Just run once command with NPM:
用NPM运行一次命令:
npm install protractor@2.5.1
npm install selenium-standalone-jar@2.45.0
This will install required packages.
这将安装所需的包。
Next modify the protractor.conf.js with selenium standalone instead of selenium address:
接下来用selenium standalone而不是selenium地址修改protractor.conf.js:
//seleniumAddress: 'http://localhost:4444/wd/hub',
seleniumServerJar: './node_modules/selenium-standalone-jar/bin/selenium-server-standalone-2.45.0.jar',
Now when you run protractor [ config file] like: protractor protractor.conf.js he will start selenium for himself and make tests.
现在当你运行量角器[配置文件]时:protractor protractor.conf.js他将为自己启动selenium并进行测试。
- Second way:
- 第二种方式:
You can implement that into build process, during build with GULP he will fire for you protractor and protractor will fire up selenium-driver himself.
您可以将其实施到构建过程中,在使用GULP构建期间,他将为您开发量角器,量角器将自己启动硒驱动器。
I see that its really tiring to you to run those command, why would you do that even, just use Gulp to make it for you.
我看到你运行这些命令真的很累,为什么你会这样做,只需用Gulp为你做。
I will explain you this on working example.
我将以工作实例向您解释这一点。
All you need is:
所有你需要的是:
Add to your (NPM) package.json file: (pick the version that suits you, this works for me.
添加到您的(NPM)package.json文件:(选择适合您的版本,这对我有用。
"gulp-protractor": "^2.1.0",
"protractor": "2.5.1",
"selenium-standalone-jar": "2.45.0",
Then you need the proper config in protractor.conf.js: You need to replace the "seleniumAddress" with direct JAR file so the protractor will fire it for you and attach to it automaticly! piece of file is:
然后你需要在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',
The seleniumServerJar is a reference path to the file which will be installed with "selenium-standalone-jar": "2.45.0", from your package.json file.
seleniumServerJar是该文件的引用路径,该文件将与package.json文件中的“selenium-standalone-jar”:“2.45.0”一起安装。
And last step is to properly make a gulp task, here's mine:
最后一步是正确地完成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);
});
Enjoy!
请享用!
#3
2
You can run testsuite as well by just adding --suite in 'args'.
您也可以通过在'args'中添加--suite来运行测试套件。
var angularProtractor = require('gulp-angular-protractor');
gulp.task('test', function (callback) {
gulp
.src([__dirname+'/public/apps/adminapp/**/**_test.js'])
.pipe(angularProtractor({
'configFile': 'public/apps/adminapp/app.test.config.js',
'debug': false,
'args': ['--suite', 'adminapp'],
'autoStartStopServer': true
}))
.on('error', function(e) {
console.log(e);
})
.on('end',callback);
});
#4
0
A complete solution, (working with Travis CI)
-
npm
configuration - npm配置
Basically, configure http-server
to start before you run gulp script. Later on you will have to run the tests via npm
, fe. npm test
or npm run <action>
if you choose other name.
基本上,配置http-server以在运行gulp脚本之前启动。稍后您必须通过npm,fe运行测试。 npm test或npm run
"devDependencies": {
"gulp-angular-protractor": "latest",
"http-server": "^0.9.0",
...
},
"scripts": {
"pretest": "npm install",
"test": "(npm start > /dev/null &) && (gulp protractor)",
"start": "http-server -a localhost -p 8000 -c-1 ./",
"dev": "(npm start > /dev/null &) && (gulp dev)"
},
- setup
gulp
withgulp-angular-protractor
- 用gulp-angular-protractor设置gulp
Define the action you want to run.
定义要运行的操作。
var gulpProtractorAngular = require('gulp-angular-protractor');
...
gulp.task('protractor', function (callback) {
gulp
.src('tests/*.js')
.pipe(gulpProtractorAngular({
'configFile': 'protractor.conf.js',
'debug': false,
'autoStartStopServer': true,
'verbose': false,
'webDriverUpdate': {
'browsers': ['ie', 'chrome']
}
}))
.on('error', function (e) {
console.log(e);
})
.on('end', callback);
});
See the above in action in GitHub project: https://github.com/atais/angular-eonasdan-datetimepicker
请参阅GitHub项目中的上述操作:https://github.com/atais/angular-eonasdan-datetimepicker