[英]protractor gulp run a single spec file
Here is my protractor conf file 这是我的量角器conf文件
exports.config = { framework: 'jasmine', exports.config = {框架:“茉莉花”,
seleniumAddress: 'http://localhost:4444/wd/hub',
specs: ['../../e2e/smoke-test/*.spec.js'],
ignoreSynchronization: 'true',
jasmineNodeOpts: {
defaultTimeoutInterval: 2500000,
allScriptsTimeout: 25000000
}
};
Here is my gulp conf file 这是我的gulp conf文件
'use strict';
var path = require('path');
var gulp = require('gulp');
// Protractor configurations to open browser
var protractor = require("gulp-protractor").protractor;
var spawn = require('child_process').spawn;
var browserSync = require('browser-sync');
var $ = require('gulp-load-plugins')();
// Downloads the selenium webdriver
gulp.task('webdriver-update', $.protractor.webdriver_update);
gulp.task('webdriver-standalone', $.protractor.webdriver_standalone);
// Protractor with selenium configuration to open browser
//run webdriver method
function runWebdriver(callback) {
spawn('webdriver-manager', ['start'], {
stdio: 'inherit'
}).once('close', callback);
}
//run protractor configurations method
function runProtractorSeleniumConfig() {
gulp.src('./**/*-page.spec.js')
.pipe(protractor({
configFile: './e2e/conf/smoke-test-conf.js'
}))
.on('error', function (e) {
throw e;
});
}
//execute protractor.config after webdriver is executed
function runWebdriverProtractor(){
// runWebdriver(runWebdriver);
runWebdriver(runProtractorSeleniumConfig);
}
//put them into
gulp.task('e2e:smoke-test', runWebdriverProtractor);
// run on dist
//gulp.task('e2e:dist', ['serve:e2e-dist', 'webdriver-update'], runProtractor);
right now I defined one task for gulp which is 现在我为gulp定义了一项任务
gulp e2e:smoke-test
I runs all specs under smoke-test what can I do if I want to run a single smoke spec file or if I want to run a single spec/test 我在烟雾测试下运行所有规格,如果我想运行单个烟雾规格文件,或者如果我想运行单个规格/测试,该怎么办?
With jasmine2 you can filter tests using a regular expression. 使用jasmine2,您可以使用正则表达式过滤测试。 Maybe you can add something like @smoke, @regressions to your tests and then only run those ones by passing the grep flag:
也许您可以在测试中添加@ smoke,@ regressions之类的东西,然后仅通过传递grep标志来运行那些测试:
describe('Test Spec @smoke', function () {
...
})
and in protractor.conf.js: 并在protractor.conf.js中:
exports.config = {
jasmineNodeOpts: {
grep: '@smoke',
}
};
I solved this by passing an individual file through gulp configuration. 我通过通过gulp配置传递单个文件来解决此问题。
function runProtractorSeleniumConfig(path) {
gulp.src(getFile(path))
.pipe(protractor({
configFile: 'ProtractorConfigFile'
}))
.on('error', function (e) {
throw e;
});
}
function getFile(ext){
if(ext == '--regression'){
return 'RegressionTestCaseFilePath'
}
else{
return 'TestCaseFilePath'
}
}
//execute protractor.config after webdriver is executed //执行webdriver后执行protractor.config
function runWebdriverProtractor(str){
// runWebdriver(runWebdriver);
runWebdriver(runProtractorSeleniumConfig(str));
}
//run smoke test commands configurations //运行烟雾测试命令配置
gulp.task('e2e:smoke-test', function(){
runWebdriverProtractor(process.argv[3])
});
now I can run regression/smokde file by simply using this 现在我可以通过简单地运行此文件来运行回归/ smokde文件
gulp e2e:smoke-test --smoke
cheers!! 干杯!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.