Angular2量角器TypeError:this.flow_.getSchedulingFrame_不是函数

时间:2017-01-09 21:01:52

标签: angular jasmine protractor

尝试使用量角器在Angular2应用上运行集成测试:

protractor.conf.js

exports.config = {
  baseUrl: 'http://localhost:3000',
  seleniumAddress: 'http://localhost:4444/wd/hub',
  specs: [
    'src/app/e2e/contact.e2e.js'
  ],
  framework: 'jasmine',
   useAllAngular2AppRoots: true
};

我的测试文件: contact.e2e.js

describe('App', function(){
  it('should render the contact section', function() {
    browser.get('/');
    expect(true).toBe(true);
  });
});

我得到的错误:

Message:
    Failed: this.flow_.getSchedulingFrame_ is not a function
  Stack:
    TypeError: this.flow_.getSchedulingFrame_ is not a function
        at promise.Promise.addCallback_ (/Users/yarivkatz/Development/workspace/bugeez/bugeez-lp-final/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:651:16)
        at promise.Promise.then (/Users/yarivkatz/Development/workspace/bugeez/bugeez-lp-final/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:592:15)
        at ManagedPromise.invokeThen_ (/Users/yarivkatz/Development/workspace/bugeez/bugeez-lp-final/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1193:12)
        at ManagedPromise.resolve_ (/Users/yarivkatz/Development/workspace/bugeez/bugeez-lp-final/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1147:16)
        at /Users/yarivkatz/Development/workspace/bugeez/bugeez-lp-final/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1083:14
        at Task.Deferred.fulfill (/Users/yarivkatz/Development/workspace/bugeez/bugeez-lp-final/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1432:7)
        at TaskQueue.onTaskComplete_ (/Users/yarivkatz/Development/workspace/bugeez/bugeez-lp-final/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2995:26)
        at subQ.once (/Users/yarivkatz/Development/workspace/bugeez/bugeez-lp-final/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2888:33)
        at TaskQueue.emit (/Users/yarivkatz/Development/workspace/bugeez/bugeez-lp-final/node_modules/protractor/node_modules/selenium-webdriver/lib/events.js:64:21)
        at TaskQueue.executeNext_ (/Users/yarivkatz/Development/workspace/bugeez/bugeez-lp-final/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:2882:12)
    From: Task: Run it("should render the contact section") in control flow
        at Object.<anonymous> (/Users/yarivkatz/Development/workspace/bugeez/bugeez-lp-final/node_modules/jasminewd2/index.js:79:14)
    From asynchronous test:
    Error
        at Suite.<anonymous> (/Users/yarivkatz/Development/workspace/bugeez/bugeez-lp-final/src/app/e2e/contact.e2e.js:11:3)
        at Object.<anonymous> (/Users/yarivkatz/Development/workspace/bugeez/bugeez-lp-final/src/app/e2e/contact.e2e.js:10:1)
        at Module._compile (module.js:556:32)
        at Object.Module._extensions..js (module.js:565:10)
        at Module.load (module.js:473:32)
        at tryModuleLoad (module.js:432:12)

我的 package.json

    "dependencies": {
        "@angular/common": "~2.2.0",
        "@angular/compiler": "~2.2.0",
        "@angular/compiler-cli": "~2.2.0",
        "@angular/core": "~2.2.0",
        "@angular/forms": "~2.2.0",
        "@angular/http": "~2.2.0",
        "@angular/platform-browser": "~2.2.0",
        "@angular/platform-browser-dynamic": "~2.2.0",
        "@angular/platform-server": "~2.2.0",
        "@angular/router": "~3.2.0",
        "@angular/upgrade": "~2.2.0",
        "@ngtools/webpack": "^1.1.4",
        "angular2-express-engine": "~2.1.0-rc.1",
        "angular2-platform-node": "~2.1.0-rc.1",
        "angular2-universal": "~2.1.0-rc.1",
        "angular2-universal-polyfills": "~2.1.0-rc.1",
        "body-parser": "^1.15.2",
        "bootstrap": "^3.3.7",
        "bootstrap-sass": "^3.3.7",
        "csurf": "^1.9.0",
        "express": "^4.14.0",
        "express-handlebars": "^3.0.0",
        "flexslider": "^2.6.3",
        "font-awesome": "^4.7.0",
        "fs": "0.0.1-security",
        "http-proxy": "^1.15.2",
        "jquery": "^3.1.1",
        "jquery.easing": "^1.4.1",
        "jquery.scrollto": "^2.1.2",
        "js.clone": "0.0.3",
        "methods": "~1.1.2",
        "modern-lru": "^1.0.8",
        "preboot": "~4.5.2",
        "rxjs": "5.0.0-beta.12",
        "scrollspy": "^1.5.0",
        "velocity": "^0.7.2",
        "velocity-animate": "^1.3.1",
        "zone.js": "~0.6.26"
      },
"devDependencies": {
    "@types/body-parser": "0.0.29",
    "@types/chai": "^3.4.34",
    "@types/compression": "0.0.29",
    "@types/cookie-parser": "^1.3.29",
    "@types/express": "^4.0.32",
    "@types/express-serve-static-core": "^4.0.33",
    "@types/hammerjs": "^2.0.32",
    "@types/jasmine": "^2.5.38",
    "@types/mime": "0.0.28",
    "@types/node": "^6.0.38",
    "@types/protractor": "^4.0.0",
    "@types/selenium-webdriver": "^2.53.35",
    "@types/serve-static": "^1.7.27",
    "@types/source-map": "^0.5.0",
    "angular2-template-loader": "^0.4.0",
    "assets-webpack-plugin": "^3.5.0",
    "awesome-typescript-loader": "^2.2.4",
    "chai": "^3.5.0",
    "compression-webpack-plugin": "^0.3.2",
    "cookie-parser": "^1.4.3",
    "css-loader": "^0.26.0",
    "css-to-string-loader": "^0.1.2",
    "extract-text-webpack-plugin": "^2.0.0-beta.4",
    "file-loader": "^0.9.0",
    "html-webpack-plugin": "^2.24.1",
    "image-webpack-loader": "^3.0.0",
    "imports-loader": "^0.6.5",
    "istanbul-instrumenter-loader": "^1.0.0",
    "jasmine": "^2.5.2",
    "jasmine-core": "^2.5.2",
    "jasmine-reporters": "^2.2.0",
    "json-loader": "^0.5.4",
    "karma": "^1.3.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-jenkins-reporter": "0.0.2",
    "karma-mocha": "^1.2.0",
    "karma-mocha-reporter": "^2.2.0",
    "karma-sourcemap-loader": "^0.3.7",
    "karma-webpack": "^1.8.0",
    "mocha": "^3.1.2",
    "mocha-jenkins-reporter": "^0.3.5",
    "mocha-junit-reporter": "^1.12.1",
    "node-sass": "^3.13.0",
    "nodemon": "^1.10.0",
    "protractor": "^4.0.11",
    "raw-loader": "^0.5.1",
    "resolve-url-loader": "^1.6.0",
    "rimraf": "^2.5.4",
    "sass-loader": "^4.0.2",
    "selenium-webdriver": "^2.47.0",
    "sinon": "^1.17.6",
    "source-map-loader": "^0.1.5",
    "string-replace-loader": "^1.0.5",
    "style-loader": "^0.13.1",
    "to-string-loader": "^1.1.5",
    "ts-helpers": "^1.1.2",
    "ts-node": "^1.3.0",
    "typescript": "2.0.2",
    "url-loader": "^0.5.7",
    "v8-lazy-parse-webpack-plugin": "^0.3.0",
    "webpack": "2.1.0-beta.27",
    "webpack-dev-middleware": "^1.8.4",
    "webpack-dev-server": "2.1.0-beta.11",
    "webpack-merge": "~0.16.0",
    "webpack-s3-plugin": "^0.9.2"
  },

奇怪的是,它只发生在我的Mac上,当我通过我的jenkins服务器上的docker运行测试时,它运行正常。 将非常感谢帮助。 提前谢谢。

更新

我的量角器不是全局的,我运行的量角器版本是:版本4.0.14

1 个答案:

答案 0 :(得分:1)

有几个要解决的问题:

devDependencies :Protractor 4.0.11使用selenium-webdriver 2.53.1。你也有不同的selenium-webdriver 2.47.0作为项目中的devDependency。

堆栈跟踪:错误selenium-webdriver/lib/goog/../webdriver/promise.js是可疑的,因为Protractor在^ 4.0.11中使用的selenium-webdriver节点模块中不存在/lib/goog/。我怀疑你使用的是旧版本的Protractor。

  • 量角器4.0.11使用selenium-webdriver 2.53.1 - 没有lib/goog/
  • 量角器2.5.1使用selenium-webdriver 2.47.0 - 确实有一个文件夹lib/goog/
  • Protractor 1.8.0使用selenium-webdriver 2.44.0 - 确实有一个文件夹lib/goog/

我会检查你是如何运行量角器的。我认为您是从全局环境运行它,应该尝试protractor --version进行验证。

也很有帮助的是将脚本添加到package.json

  "scripts": {
    "e2e": "protractor some/path/to/conf.js"
  }

然后使用npm run e2e执行此操作。这将确保您使用项目中项目node_modules的量角器。

<强>更新

上面的答案,我改变了2.47.0确实有路径/lib/goog/。我真的很晚才回答,可能写错了。这可能是因为我做了npm i -S selenium-webdriver@^2.47.0。不知怎的,你已经声明你想要^ 2.47.0但是如果你收缩包装2.47.0则会阻止胡萝卜下载最后一个次要版本。

对答案的改进。下面的堆栈跟踪引用了两个不同版本的selenium-webdriver。 selenium-webdriver是Protractor的一部分,是另一个版本。不在量角器中的selenium-webdriver指的是路径lib/goog/

at promise.Promise.addCallback_ (/Users/yarivkatz/Development/workspace/bugeez/bugeez-lp-final/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:651:16)
        at promise.Promise.then (/Users/yarivkatz/Development/workspace/bugeez/bugeez-lp-final/node_modules/selenium-webdriver/lib/goog/../webdriver/promise.js:592:15)
        at ManagedPromise.invokeThen_ (/Users/yarivkatz/Development/workspace/bugeez/bugeez-lp-final/node_modules/protractor/node_modules/selenium-webdriver/lib/promise.js:1193:12)

如上所述,在更新中,我相信你的selenium-webdriver版本中有一些东西被锁定了。另外,因为你有两个版本的selenium-webdriver,你正在调用node_modules/protractor/node_modules/selenium-webdriver并以某种方式调用node_modules/selenium-webdriver/lib/goog/

请删除devDependency,将其从shrinkwrap中删除,然后重新安装依赖项。