Angular 量角器:ng e2e:如何解决;错误:连接ETIMEDOUT“;错误?

Angular 量角器:ng e2e:如何解决;错误:连接ETIMEDOUT“;错误?,angular,protractor,angular-cli,Angular,Protractor,Angular Cli,我开发了Angular教程应用程序。之后,我为组件编写了测试。应用程序和组件测试进展良好。现在我想用量角器开发E2E测试,但我无法让它们运行 每次在命令行上运行ng e2e,我都会得到以下输出: $ ng e2e ** NG Live Development Server is listening on localhost:49152, open your browser on http://localhost:49152/ ** Date: 2017-09-26T14:51:12.962Z H

我开发了Angular教程应用程序。之后,我为组件编写了测试。应用程序和组件测试进展良好。现在我想用量角器开发E2E测试,但我无法让它们运行

每次在命令行上运行
ng e2e
,我都会得到以下输出:

$ ng e2e
** NG Live Development Server is listening on localhost:49152, open your browser on http://localhost:49152/ **
Date: 2017-09-26T14:51:12.962Z
Hash: ef70100f8d31703b6b85
Time: 8035ms
chunk {inline} inline.bundle.js, inline.bundle.js.map (inline) 5.83 kB [entry] [rendered]
chunk {main} main.bundle.js, main.bundle.js.map (main) 3.16 MB {inline} [initial] [rendered]
chunk {polyfills} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 209 kB {inline} [initial] [rendered]
chunk {styles} styles.bundle.js, styles.bundle.js.map (styles) 11.6 kB {inline} [initial] [rendered]
(node:13556) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.

webpack: Compiled successfully.
events.js:182
  throw er; // Unhandled 'error' event
  ^

Error: connect ETIMEDOUT 216.58.205.112:443
    at Object._errnoException (util.js:1026:11)
    at _exceptionWithHostPort (util.js:1049:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1174:14)
有关我的设置的一些有用信息:

  • 该项目是使用Anguliar CLI创建的
  • 量角器安装在全球和本地
  • 以下文件位于
    节点模块/webdriver管理器/selenium
    目录中:
    chromedriver_2.32.exe、chromedriver_2.32.zip、chrome-response.xml、gecko-response.json、selenium-server-standalone-3.5.3.jar、standalone response.xml
  • 我使用代理属性运行
    webdriver管理器更新
  • 如果使用正在运行的Selenium网格或使用
    directConnect:true
    配置运行该命令,则没有区别
  • 由于浏览器设置为Chrome(Firefox也有同样的问题)
  • 操作系统:Windows 10,浏览器:Chrome 51.0.2704.106 m(64位)
dragrator.conf.js
文件:

// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts

const { SpecReporter } = require('jasmine-spec-reporter');

exports.config = {
  allScriptsTimeout: 11000,
  specs: [
    './e2e/**/*.e2e-spec.ts'
  ],
  capabilities: {
    'browserName': 'chrome'
  },
  directConnect: true,
  baseUrl: 'http://localhost:4200/',
  /*seleniumAddress: 'http://localhost:4444/wd/hub',*/
  directConnect: true,
  framework: 'jasmine',
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000,
    print: function() {}
  },
  onPrepare() {
    require('ts-node').register({
      project: 'e2e/tsconfig.e2e.json'
    });
    jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
  }
};
{
  "name": "angular-tour-of-heroes",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^4.2.4",
    "@angular/common": "^4.2.4",
    "@angular/compiler": "^4.2.4",
    "@angular/core": "^4.2.4",
    "@angular/forms": "^4.2.4",
    "@angular/http": "^4.2.4",
    "@angular/platform-browser": "^4.2.4",
    "@angular/platform-browser-dynamic": "^4.2.4",
    "@angular/router": "^4.2.4",
    "core-js": "^2.4.1",
    "rxjs": "^5.4.2",
    "zone.js": "^0.8.14"
  },
  "devDependencies": {
    "@angular/cli": "1.4.2",
    "@angular/compiler-cli": "^4.2.4",
    "@angular/language-service": "^4.2.4",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "angular-in-memory-web-api": "^0.4.6",
    "codelyzer": "~3.1.1",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-firefox-launcher": "^1.0.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "^5.1.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.3.2",
    "typescript": "~2.3.3"
  }
}
package.json
文件:

// Protractor configuration file, see link for more information
// https://github.com/angular/protractor/blob/master/lib/config.ts

const { SpecReporter } = require('jasmine-spec-reporter');

exports.config = {
  allScriptsTimeout: 11000,
  specs: [
    './e2e/**/*.e2e-spec.ts'
  ],
  capabilities: {
    'browserName': 'chrome'
  },
  directConnect: true,
  baseUrl: 'http://localhost:4200/',
  /*seleniumAddress: 'http://localhost:4444/wd/hub',*/
  directConnect: true,
  framework: 'jasmine',
  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000,
    print: function() {}
  },
  onPrepare() {
    require('ts-node').register({
      project: 'e2e/tsconfig.e2e.json'
    });
    jasmine.getEnv().addReporter(new SpecReporter({ spec: { displayStacktrace: true } }));
  }
};
{
  "name": "angular-tour-of-heroes",
  "version": "0.0.0",
  "license": "MIT",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^4.2.4",
    "@angular/common": "^4.2.4",
    "@angular/compiler": "^4.2.4",
    "@angular/core": "^4.2.4",
    "@angular/forms": "^4.2.4",
    "@angular/http": "^4.2.4",
    "@angular/platform-browser": "^4.2.4",
    "@angular/platform-browser-dynamic": "^4.2.4",
    "@angular/router": "^4.2.4",
    "core-js": "^2.4.1",
    "rxjs": "^5.4.2",
    "zone.js": "^0.8.14"
  },
  "devDependencies": {
    "@angular/cli": "1.4.2",
    "@angular/compiler-cli": "^4.2.4",
    "@angular/language-service": "^4.2.4",
    "@types/jasmine": "~2.5.53",
    "@types/jasminewd2": "~2.0.2",
    "@types/node": "~6.0.60",
    "angular-in-memory-web-api": "^0.4.6",
    "codelyzer": "~3.1.1",
    "jasmine-core": "~2.6.2",
    "jasmine-spec-reporter": "~4.1.0",
    "karma": "~1.7.0",
    "karma-chrome-launcher": "~2.1.1",
    "karma-cli": "~1.0.1",
    "karma-coverage-istanbul-reporter": "^1.2.1",
    "karma-firefox-launcher": "^1.0.1",
    "karma-jasmine": "~1.1.0",
    "karma-jasmine-html-reporter": "^0.2.2",
    "protractor": "^5.1.2",
    "ts-node": "~3.2.0",
    "tslint": "~5.3.2",
    "typescript": "~2.3.3"
  }
}
这是我第一次尝试用角度和量角器开发E2E测试

谢谢你的支持

更新

我不知道如果我运行
nge2e
,将执行
webdriver管理器更新。所以我尝试了
nge2e——不更新webdriver
,使用这个命令,上面的错误就不会再出现了。我认为出现错误是因为未设置代理,并且webdriver管理器无法运行更新

然而,现在我得到了一个新的错误。下面是完整的输出:

$ ng e2e --no-webdriver-update
** NG Live Development Server is listening on localhost:49152, open your browser on http://localhost:49152/ **
Date: 2017-09-27T06:50:31.482Z
Hash: ef70100f8d31703b6b85
Time: 8513ms
chunk {inline} inline.bundle.js, inline.bundle.js.map (inline) 5.83 kB [entry] [rendered]
chunk {main} main.bundle.js, main.bundle.js.map (main) 3.16 MB {inline} [initial] [rendered]
chunk {polyfills} polyfills.bundle.js, polyfills.bundle.js.map (polyfills) 209 kB {inline} [initial] [rendered]
chunk {styles} styles.bundle.js, styles.bundle.js.map (styles) 11.6 kB {inline} [initial] [rendered]
(node:12764) [DEP0022] DeprecationWarning: os.tmpDir() is deprecated. Use os.tmpdir() instead.

webpack: Compiled successfully.
[08:50:31] I/launcher - Running 1 instances of WebDriver
[08:50:31] I/direct - Using ChromeDriver directly...
[08:50:31] E/direct - Error code: 135
[08:50:31] E/direct - Error message: Could not find update-config.json. Run 'webdriver-manager update' to download binaries.
[08:50:31] E/direct - Error: Could not find update-config.json. Run 'webdriver-manager update' to download binaries.
    at Direct.getNewDriver (D:\gitrepos\angular-tour-of-heroes\node_modules\protractor\built\driverProviders\direct.js:63:31)
    at Runner.createBrowser (D:\gitrepos\angular-tour-of-heroes\node_modules\protractor\built\runner.js:195:43)
    at q.then.then (D:\gitrepos\angular-tour-of-heroes\node_modules\protractor\built\runner.js:339:29)
    at _fulfilled (D:\gitrepos\angular-tour-of-heroes\node_modules\protractor\node_modules\q\q.js:834:54)
    at self.promiseDispatch.done (D:\gitrepos\angular-tour-of-heroes\node_modules\protractor\node_modules\q\q.js:863:30)
    at Promise.promise.promiseDispatch (D:\gitrepos\angular-tour-of-heroes\node_modules\protractor\node_modules\q\q.js:796:13)
    at D:\gitrepos\angular-tour-of-heroes\node_modules\protractor\node_modules\q\q.js:556:49
    at runSingle (D:\gitrepos\angular-tour-of-heroes\node_modules\protractor\node_modules\q\q.js:137:13)
    at flush (D:\gitrepos\angular-tour-of-heroes\node_modules\protractor\node_modules\q\q.js:125:13)
    at _combinedTickCallback (internal/process/next_tick.js:131:7)
    at process._tickCallback (internal/process/next_tick.js:180:9)
[08:50:31] E/launcher - Process exited with error code 135

好的,我能解决这个问题。这就是我所做的

ng e2e
运行
webdriver-manager-update
命令。在我的例子中,这导致了
ETIMEDOUT
问题,因为在没有代理的环境中,它无法下载文件。相反,我必须使用
nge2e——不更新webdriver

现在我遇到了
找不到update config.json
错误

使用
--proxy
参数更新webdriver manager似乎无法下载所有内容和/或进行正确的操作。我必须设置环境变量
HTTP\u PROXY
HTTPS\u PROXY
,并运行命令
webdriver manager update--ignore\u ssl


现在量角器正在工作。

我发现
webdriver管理器更新
尊重
HTTPS\u代理
环境变量。尝试使用您的(公司)代理服务器设置
HTTPS\u PROXY
环境变量
http://********:80
重新启动VS代码或命令提示符(以拾取更改),您应该可以毫无问题地运行e2e测试。

如果您在webstorm或Intellij编辑器中。您可以设置HTTPS_代理变量,也可以在webstorm终端中设置

SET https_proxy=http://yourcompanydomain.com:portnumber
SET http_proxy=http://yourcompanydomain.com:portnumber 
然后在终端中运行以下命令

ng e2e

在我的案例中,问题与公司代理有关。
webdriver manager update
命令遇到超时。无论是在.npmrc中设置代理还是像下面这样使用命令行都不起作用

无效解决方案:

SET http_proxy=http://xxx.xxxxxx.xxx:8080

SET https_proxy=http://xxx.xxxxxx.xxx:8080
工作解决方案:为命令提供一个
--proxy
标志:

webdriver-manager update --proxy=http://xxx.xxxxxx.xxx:8080

这是

中的正确答案,为我们做了诀窍,事实上,如果您支持corporate proxy,这将解决驱动程序更新问题。这很有效!我将HTTP_代理和HTTPS_代理设置为我的公司代理,然后使用Angular CLI创建了一个新项目。现在,我只需使用ng e2e命令即可运行测试,无需禁用webdriver更新和/或使用--proxy标志手动更新。