有人可以让我知道如何将selenium服务器自动启动,而无需在单独的窗口中使用start命令手动启动它。我想测试首先启动服务器,然后自动运行
这是我的conf文件。
var HtmlReporter = require('protractor-html-screenshot-reporter');
var path = require('path');
// A reference configuration file.
exports.config = {
// ----- How to setup Selenium -----
//
// There are three ways to specify how to use Selenium. Specify one of the
// following:
//webdriver-manager start --standalone
// 1. seleniumServerJar - to start Selenium Standalone locally.
// 2. seleniumAddress - to connect to a Selenium server which is already
// running.
// 3. sauceUser/sauceKey - to use remote Selenium servers via SauceLabs.
seleniumAddress: 'http://localhost:4444/wd/hub',
// The location of the selenium standalone server .jar file.
seleniumServerJar: 'node_modules/protractor/selenium/selenium-server-standalone-2.40.0.jar',
// The port to start the selenium server on, or null if the server should
// find its own unused port.
seleniumPort: null,
// Chromedriver location is used to help the selenium standalone server
// find chromedriver. This will be passed to the selenium jar as
// the system property webdriver.chrome.driver. If null, selenium will
// attempt to find chromedriver using PATH.
chromeDriver: 'node_modules/grunt-protractor-runner/node_modules/protractor/node_modules/selenium-webdriver/',
// Additional command line options to pass to selenium. For example,
// if you need to change the browser timeout, use
// seleniumArgs: ['-browserTimeout=60'],
seleniumArgs: [],
// If sauceUser and sauceKey are specified, seleniumServerJar will be ignored.
// The tests will be run remotely using SauceLabs.
sauceUser: null,
sauceKey: null,
// ----- What tests to run -----
//
// Spec patterns are relative to the location of this config.
specs: [
'src/test/webapp/uitest/index.js'
],
// ----- Capabilities to be passed to the webdriver instance ----
//
// For a full list of available capabilities, see
// https://code.google.com/p/selenium/wiki/DesiredCapabilities
// and
// https://code.google.com/p/selenium/source/browse/javascript/webdriver/capabilities.js
capabilities: {
'browserName': 'chrome'
},
// A base URL for your application under test. Calls to protractor.get()
// with relative paths will be prepended with this.
baseUrl: 'http://localhost:8081',
// Selector for the element housing the angular app - this defaults to
// body, but is necessary if ng-app is on a descendant of <body>
rootElement: 'body',
onPrepare: function() {
global.isAngularSite = function(flag) {
browser.ignoreSynchronization = !flag;
};
// Add a reporter and store screenshots to `screnshots`:
jasmine.getEnv().addReporter(new HtmlReporter({
baseDirectory: 'screenshots',
pathBuilder: function pathBuilder(spec, descriptions, results, capabilities) {
var monthMap = {
"1": "Jan",
"2": "Feb",
"3": "Mar",
"4": "Apr",
"5": "May",
"6": "Jun",
"7": "Jul",
"8": "Aug",
"9": "Sep",
"10": "Oct",
"11": "Nov",
"12": "Dec"
};
var currentDate = new Date(),
currentHoursIn24Hour = currentDate.getHours(),
currentTimeInHours = currentHoursIn24Hour>12? currentHoursIn24Hour-12: currentHoursIn24Hour,
totalDateString = currentDate.getDate()+'-'+ monthMap[currentDate.getMonth()]+ '-'+(currentDate.getYear()+1900) +
'-'+ currentTimeInHours+'h-' + currentDate.getMinutes()+'m';
return path.join(totalDateString,capabilities.caps_.browserName, descriptions.join('-'));
}
}));
},
// ----- Options to be passed to minijasminenode -----
jasmineNodeOpts: {
// onComplete will be called just before the driver quits.
onComplete: null,
// If true, display spec names.
isVerbose: false,
// If true, print colors to the terminal.
showColors: true,
// If true, include stack traces in failures.
includeStackTrace: true,
// Default time to wait in ms before a test fails.
defaultTimeoutInterval: 60000
},
};
我收到此错误
[INFO] Running "protractor_webdriver:start" (protractor_webdriver) task
[INFO] Starting Selenium server
[INFO] Warning: Selenium Standalone is not present. Install with
webdriver-manager update --standalone
[INFO] Use --force to continue.
[INFO]
[INFO] Aborted due to warnings.
答案 0 :(得分:1)
我们使用Gulp,这就是它的样子 -
'use strict';
var global = {
app_files: {
specs: './specs/**/*.js'
},
folders: {
specs: './specs'
}
};
var gulp = require('gulp');
var jshint = require('gulp-jshint');
var stylish = require('jshint-stylish');
var beautify = require('gulp-jsbeautifier');
var protractor = require('gulp-protractor').protractor;
// Download and update the selenium driver
var webdriver_update = require('gulp-protractor').webdriver_update;
var webdriver_standalone = require('gulp-protractor').webdriver_standalone;
// Downloads the selenium webdriver
gulp.task('webdriver_update', webdriver_update);
// Runs the selenium webdriver
gulp.task('webdriver_standalone', webdriver_standalone);
// Lint spec files
gulp.task('lint', function() {
return gulp.src(global.app_files.specs).pipe(jshint()).pipe(jshint.reporter(stylish)).pipe(jshint.reporter('fail'));
});
// Beautify spec files
gulp.task('beautify', function() {
return gulp.src(global.app_files.specs).pipe(beautify({
config: '.jsbeautifyrc'
})).pipe(gulp.dest(global.folders.specs));
});
gulp.task('e2e:local', ['lint', 'webdriver_update'], function() {
gulp.src([global.app_files.specs], {
read: false
}).pipe(protractor({
configFile: 'protractor.conf.js'
})).on('error', function(e) {
throw e;
});
});
gulp.task('e2e', ['e2e:local']);
并在量角器中运行 - gulpe2e:local并确保specs文件的路径正确。
这应该有效。你应该先安装gulp!
答案 1 :(得分:0)
使用seleniumAddress
或seleniumServerJar
我想我在某处读到如果您使用seleniumAddress
,它会忽略seleniumServerJar
和seleniumPort