Protractor not connected to DevTools

2019-06-15 14:32发布

问题:

How can I use the Chrome developer tools to inspect my page while it's running from Protractor? When I try to open the devtools, I get this error from protractor:

     UnknownError: disconnected: not connected to DevTools
  (Session info: chrome=35.0.1916.114)
  (Driver info: chromedriver=2.10.267518,platform=Linux 3.5.0-49-generic x86_64)

回答1:

You can't because webdriver uses the developer tools to communicate with chrome. If the dev tools window is open then your can't execute any protractor code.

https://sites.google.com/a/chromium.org/chromedriver/help/devtools-window-keeps-closing

I would advice you to duplicate the tab or pause your test either with browser.sleep(ms) or browser.debugger()



回答2:

There is a new pause function that can be used to open the dev tools and e.g. taking a heap snapshot. It pauses the test execution until you continue the execution from the command window.

More details here:

  • http://angular.github.io/protractor/#/api?view=Protractor.prototype.pause
  • http://ng-learn.org/2014/04/Pausing-Protractor/

To use it, simply add the following to your test code:

browser.pause();

Once you're ready to continue the test, type in d followed by Enter in the paused command window/terminal.