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

时间:2017-09-26 15:38:04

标签: angular protractor angular-cli

我开发了Tour of Heroes Angular教程应用程序。之后我写了组件的测试。应用程序和组件测试都很好。现在我想用Protractor开发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
  • 创建的
  • 量角器已在全球和本地安装
  • 以下文件位于node_modules/webdriver-manager/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-manager update
  • 如果我使用正在运行的Selenium Grid或directConnect: true配置
  • 运行该命令没有任何区别
  • 浏览器已设置Chrome(Firefox有同样的问题)
  • 操作系统:Windows 10,浏览器:Chrome 51.0.2704.106 m(64位)

protractor.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 } }));
  }
};

package.json档案:

{
  "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"
  }
}

这是我第一次尝试使用Angular和Protractor开发E2E测试。

感谢您的支持!

更新

如果我运行webdriver-manager update,我不知道ng e2e会被执行。所以我尝试ng e2e --no-webdriver-update并使用此命令,上面的错误不再出现了。我认为出现错误是因为没有设置代理,并且webdriver-manager无法运行更新。

但是,现在我收到了一个新错误。这是完整的输出:

$ 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

4 个答案:

答案 0 :(得分:7)

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

ng e2e运行webdriver-manager update命令。在我的情况下,这导致ETIMEDOUT问题,因为在没有代理的环境中,它无法下载文件。相反,我必须使用ng e2e --no-webdriver-update

现在我遇到了Could not find update-config.json错误。

使用--proxy参数更新webdriver-manager似乎没有下载所有内容和/或更正。我必须设置环境变量HTTP_PROXYHTTPS_PROXY并运行命令webdriver-manager update --ignore_ssl

现在量角器正在工作。

答案 1 :(得分:4)

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

答案 2 :(得分:1)

如果您使用的是Webstorm或Intellij编辑器。您可以设置HTTPS_PROXY变量,也可以在Webstorm终端中

SET https_proxy=http://yourcompanydomain.com:portnumber
SET http_proxy=http://yourcompanydomain.com:portnumber 

然后在终端机中运行以下命令

ng e2e

它肯定可以工作

答案 3 :(得分:0)

就我而言,问题与公司代理人有关。 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

这是来自webdriver-manager update throwing Error: connect ETIMEDOUT

的正确答案