有没有办法在命令链中调试 nightwatch,或者在 chrome DevTools 中调试注入(inject)的代码?
例如,我想调试“window”对象:
我使用 Chrome 版本 59.0.3071.115。 根据ChromeDriver - WebDriver for Chrome一旦 DevTools 打开,DevTools 总是会与 ChromeDriver 断开连接。意思是,如果我在执行命令(图像)中注入(inject)代码,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 .
异常(exception):
除了execute命令外,因为nightwatch将指定的脚本直接注入(inject)到浏览器中,浏览器就会在那里执行。此外,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
关于node.js - nightwatch - 使用 Node.js 和 Chrome 进行调试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45456772/