什么线导致这个Protractor错误?

时间:2015-03-12 01:20:10

标签: error-handling webdriver jasmine protractor end-to-end

Protractor是否有办法在控制台日志中显示错误发生在哪一行?我刚收到这种消息:

Message:
    Failed: Cannot call method 'click' of undefined
  Stack:
    Error: Failed: Cannot call method 'click' of undefined
        at /usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:104:16
        at /usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/base.js:1582:15
        at [object Object].webdriver.promise.ControlFlow.runInNewFrame_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1654:20)
        at notify (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:465:12)

1 spec, 1 failure

很难弄清楚我是否有这么多点击命令。我正在运行Protractor 1.8.0。

这是我的protractor.conf.js

exports.config = {
  framework: 'jasmine2',

  seleniumAddress: 'http://11.111.1.11:4444/wd/hub',

  multiCapabilities: [{
    'browserName': 'chrome',
    'chromeOptions': {
        args: ['--test-type']
    }
  }],

  specs: ['./tests/my_test/*_spec.js'],

  onPrepare: function(){

      global.EC = protractor.ExpectedConditions;

      browser.manage().window().maximize();

      var jasmineReporters = require('jasmine-reporters');

      jasmine.getEnv().addReporter(new jasmineReporters.JUnitXmlReporter({
        consolidateAll: true,
        filePrefix: 'tests_xmloutput',
        savePath: './test_results_report'
      }));
  },

  jasmineNodeOpts: {
    showColors: true,
    defaultTimeoutInterval: 30000
  }
};

完整的错误消息是:

Failures:
1) test name description
  Message:
    Failed: Cannot call method 'click' of undefined
  Stack:
    Error: Failed: Cannot call method 'click' of undefined
        at /usr/local/lib/node_modules/protractor/node_modules/jasminewd2/index.js:104:16
        at /usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/goog/base.js:1582:15
        at [object Object].webdriver.promise.ControlFlow.runInNewFrame_ (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:1654:20)
        at notify (/usr/local/lib/node_modules/protractor/node_modules/selenium-webdriver/lib/webdriver/promise.js:465:12)

1 spec, 1 failure
Finished in 3.206 seconds
[launcher] 0 instance(s) of WebDriver still running
[launcher] chrome #1 failed 1 test(s)
[launcher] overall: 1 failed spec(s)
[launcher] Process exited with error code 1

规范文件/测试的内容将是:

HeaderNavigationPartialPage.myAppButton.click();
LeftNavigationPartialPage.myAppToolsLink.ERROR-ON-PURPOSE.click();  
browser.wait(EC.elementToBeClickable(LeftNavigationPartialPage.myAppSearchLink), 10000);
LeftNavigationPartialPage.myAppSearchLink.click();

1 个答案:

答案 0 :(得分:4)

以下是protractor使用引擎盖下jasminewd项目的相关问题:

此问题现已修复,jasmine升级为>=2.3.1

您应该做的是protractor升级为>=2.1.0


旧答案:

作为解决方法,请返回jasmine 1.x

exports.config = {
    framework: 'jasmine',

    ...
}