本文介绍了使用gulp运行量角器和硒时出现问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 'use 

严格';
var global = {
app_files:{
spec:'./e2e/**/*_spec.js'
},
文件夹:{
规格:'./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;
//下载并更新selenium驱动
var webdriver_update = require('gulp-protractor')。webdriver_update;
var webdriver_standalone = require('gulp-protractor')。webdriver_standalone;
//下载selenium webdriver
gulp.task('webdriver_update',webdriver_update);
//运行selenium webdriver
gulp.task('webdriver_standalone',webdriver_standalone);
// Lint spec文件
gulp.task('lint',function(){
return gulp.src(global.app_files.specs).pipe(jshint())。pipe jshint.reporter(时尚))。pipe(jshint.reporter('fail'));
});
//美化spec文件
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(量角器({
configFile:'protractor.conf.js'
}))。on('error',function(e){
扔e;
});
});
gulp.task('e2e',['e2e:local']);

但是当我使用-gulpe2e:local运行量角器时,出现以下错误:

  MacBook-Pro:spec sab $ protractor protractor.conf.js -gulpe2e:local 
在http://使用selenium服务器127.0.0.1:4444/wd/hub
[launcher]运行1个WebDriver实例

/ usr / local / lib / node_modules / protractor / node_modules / selenium-webdriver / http / index。 js:174
callback(new Error(message));
^
错误:ECONNREFUSED在ClientRequest中连接ECONNREFUSED 127.0.0.1:4444
<匿名> (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/http/index.js:174:16)在ClientRequest处的emitOne(events.js:77:13)

。在Socket.socketErrorListener(_http_client.js:265:9)处发射(events.js:169:7)
在emit.ene(events.js:77:13)处
在Socket.emit处
(events.js:169:7)
at emitErrorNT(net.js:1256:8)
at nextTickCallbackWith2Args(node.js:455:9)
at process._tickCallback(node。 js:369:17)
From:Task:WebDriver.createSession()
at Function.webdriver.WebDriver.acquireSession_(/ usr / local / lib / node_modules / protractor / node_modules / selenium-webdriver / lib /webdriver/webdriver.js:157:22)
在Function.webdriver.WebDriver.createSession(/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:131 :30)
at [object Object] .Builder.build(/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/builder.js:445:22)
at [object Object ] .D riverProvider.getNewDriver(/usr/local/lib/node_modules/protractor/lib/driverProviders/driverProvider.js:38:7)
at [object Object] .Runner.createBrowser(/ usr / local / lib / node_modules / /usr/local/lib/node_modules/protractor/lib/runner.js:276:21
在_fulfilled(/ usr / local / lib) /node_modules/protractor/node_modules/q/q.js:797:54)self.promiseDispatch.done中的
(/usr/local/lib/node_modules/protractor/node_modules/q/q.js:826:30 )$ Promise.promise.promiseDispatch
(/usr/local/lib/node_modules/protractor/node_modules/q/q.js:759:13)
位于/ usr / local / lib / node_modules / protractor /node_modules/q/q.js:525:49
[launcher]进程已退出,错误代码为1



$ p




$ b

谢谢

这个错误表明量角器试图连接到webdriver,并且TCP连接离子被拒绝。这可能是因为webdriver没有运行。



您的gulp文件定义了启动webdriver的任务:

  //运行selenium webdriver 
gulp.task('webdriver_standalone',webdriver_standalone);

运行它:

  gulp webdriver_standalone 

保持运行状态,然后运行gulp任务以启动测试。

或者,您可以让量角器为您启动和停止webdriver。从:



  // selenium server jar()的文件路径
seleniumServerJar:'./node_modules/protractor/selenium/selenium-server-standalone-2.45.0。 jar',
// seleniumAddress:'http:// localhost:4444 / wd / hub',


I am new to protractor and also new to gulp task.I had gulp file which looks like this:

    'use strict';
var global = {
    app_files: {
        spec: './e2e/**/*_spec.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']);

But when I run in protractor with - gulpe2e:local I got the following error:

MacBook-Pro:spec sab$ protractor protractor.conf.js -gulpe2e:local
Using the selenium server at http://127.0.0.1:4444/wd/hub
[launcher] Running 1 instances of WebDriver

/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/http/index.js:174
      callback(new Error(message));
               ^
Error: ECONNREFUSED connect ECONNREFUSED 127.0.0.1:4444
    at ClientRequest.<anonymous> (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/http/index.js:174:16)
    at emitOne (events.js:77:13)
    at ClientRequest.emit (events.js:169:7)
    at Socket.socketErrorListener (_http_client.js:265:9)
    at emitOne (events.js:77:13)
    at Socket.emit (events.js:169:7)
    at emitErrorNT (net.js:1256:8)
    at nextTickCallbackWith2Args (node.js:455:9)
    at process._tickCallback (node.js:369:17)
From: Task: WebDriver.createSession()
    at Function.webdriver.WebDriver.acquireSession_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:157:22)
    at Function.webdriver.WebDriver.createSession (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/webdriver.js:131:30)
    at [object Object].Builder.build (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/builder.js:445:22)
    at [object Object].DriverProvider.getNewDriver (/usr/local/lib/node_modules/protractor/lib/driverProviders/driverProvider.js:38:7)
    at [object Object].Runner.createBrowser (/usr/local/lib/node_modules/protractor/lib/runner.js:186:37)
    at /usr/local/lib/node_modules/protractor/lib/runner.js:276:21
    at _fulfilled (/usr/local/lib/node_modules/protractor/node_modules/q/q.js:797:54)
    at self.promiseDispatch.done (/usr/local/lib/node_modules/protractor/node_modules/q/q.js:826:30)
    at Promise.promise.promiseDispatch (/usr/local/lib/node_modules/protractor/node_modules/q/q.js:759:13)
    at /usr/local/lib/node_modules/protractor/node_modules/q/q.js:525:49
[launcher] Process exited with error code 1

Any help will be really appreciated.

Thanks

Sabbu

解决方案

The error indicates that protractor is attempting to connect to the webdriver, and the TCP connection is refused. This is probably because the webdriver is not running.

Your gulp file defines a task for starting the webdriver:

// Runs the selenium webdriver
gulp.task('webdriver_standalone', webdriver_standalone);

To run it:

gulp webdriver_standalone

Leave it running, and then run the gulp task to start the tests.

Alternatively, you can let protractor start and stop the webdriver for you. From the documentation:

// The file path to the selenium server jar ()
seleniumServerJar: './node_modules/protractor/selenium/selenium-server-standalone-2.45.0.jar',
// seleniumAddress: 'http://localhost:4444/wd/hub',

这篇关于使用gulp运行量角器和硒时出现问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 19:19
查看更多