Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What line is causing this Protractor error?

Is there a way for Protractor to show in the console log what line the error occurred on? I just get this type of message:

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

It's hard to figure out if I have so many click commands. I'm running Protractor 1.8.0.

Here is my 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
  }
};

The complete error message would be:

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

The content of the spec file/test would be:

HeaderNavigationPartialPage.myAppButton.click();
LeftNavigationPartialPage.myAppToolsLink.ERROR-ON-PURPOSE.click();  
browser.wait(EC.elementToBeClickable(LeftNavigationPartialPage.myAppSearchLink), 10000);
LeftNavigationPartialPage.myAppSearchLink.click();
like image 517
awaken Avatar asked Mar 12 '15 01:03

awaken


1 Answers

Here is a related issue at jasminewd project that protractor uses under-the-hood:

  • Stack traces for Jasmine2 don't include asynchronous events

The issue is now fixed, with jasmine upgrade to >=2.3.1.

What you should do is to upgrade protractor to >=2.1.0.


Old answer:

As a workaround, get back to jasmine 1.x:

exports.config = {
    framework: 'jasmine',

    ...
}
like image 187
alecxe Avatar answered Sep 22 '22 12:09

alecxe