Selenium webdriver 使用量角器或grunt启动Selenium

Selenium webdriver 使用量角器或grunt启动Selenium,selenium-webdriver,gruntjs,protractor,Selenium Webdriver,Gruntjs,Protractor,有人能告诉我如何集成selenium服务器以自动启动,而无需使用start命令在单独的窗口中手动启动它。我希望测试首先启动服务器,然后自动运行 这是我的conf文件 var HtmlReporter = require('protractor-html-screenshot-reporter'); var path = require('path'); // A reference configuration file. exports.config = { // -----

有人能告诉我如何集成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
},
};

我们用大口喝这个,看起来是这样的-

'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

使用
seleniumAddress
seleniumServerJar


我想我在某个地方读到过,如果您使用
seleniumAddress
它将忽略
seleniumServerJar
SeleniumImport

我在运行“Gragorator\u webdriver:start”(Gragorator\u webdriver)任务[INFO]启动Selenium服务器[INFO]时收到此错误[INFO]警告:Selenium Standalone不存在。使用webdriver管理器更新安装--独立[INFO]使用--强制继续。[INFO][INFO]由于警告而中止。您创建了任务
webdriver\u standalone
,但它是否正在任何地方使用?或者您只是在e2e测试中使用seleniumServerJar?
'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']);