What line is causing this Protractor error?

匿名 (未验证) 提交于 2019-12-03 02:26:02

问题:

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(); 

回答1:

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

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',      ... } 


易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!