nightwatch - 使用 node.js 和 Chrome 进行调试

nightwatch - debugging with node.js and Chrome

有没有办法在命令链中调试 nightwatch,或者在 chrome DevTools 中调试注入的代码?

例如,我想调试 "window" 对象:

我使用 chrome 版本 59.0.3071.115。 根据 ChromeDriver - WebDriver for Chrome,一旦 DevTools 打开,DevTools 总是与 ChromeDriver 断开连接。意思是,如果我在执行命令(图像)中注入代码,DevTools 将关闭并且我必须再次重新打开它?意思是,我什至不能在前端调试它?

谢谢!

显然,在命令队列中调试或设置断点的唯一方法是通过回调,如下例所示。

Setting a breakpoint to inspect a page in browser

Sometimes it is important to inspect a page in browser in the middle of a test case run. For example, to verify used selectors. To pause execution at the right moment set a breakpoint inside a callback:

   browser.perform(function () {
   console.log('dummy statement'); // install a breakpoint here   });

示例取自 https://github.com/nightwatchjs/nightwatch/wiki/Understanding-the-Command-Queue

除了:

execute 命令除外,因为nightwatch 将指定的脚本直接注入浏览器,将在那里执行。此外,chrome 每页只允许一个 DevTools,因此它会在每次必须执行命令时尝试重新打开 DevTools。

DevTools window keeps closing

This is normal.

When you open the DevTools window, ChromeDriver is automatically disconnected. When ChromeDriver receives a command, if disconnected, it will attempt to close the DevTools window and reconnect.

Chrome's DevTools only allows one debugger per page. As of 2.x, ChromeDriver is now a DevTools debugging client. Previous versions of ChromeDriver used a different automation API that is no longer supported in Chrome 29.

If you need to inspect something in DevTools, the best you can do now is pause your test so that ChromeDriver won't close DevTools. When you are done inspecting things in Chrome, you can unpause your test and ChromeDriver will close the window and continue.

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