Reputation: 597
Is there a way to debug nightwatch even within the command chains, or debug the injected code in chrome DevTools?
For instance, I want to debug the "window" object:
I use chrome Version 59.0.3071.115. According to ChromeDriver - WebDriver for Chrome the DevTools is always disconnected from ChromeDriver as soon as the DevTools opens. Meaning, if I inject the code within the execute command (images) the DevTools will close and I have to reopen it again? Meaning, I cannot even debug it in the front end?
Thanks!
Upvotes: 2
Views: 1789
Reputation: 597
Apparently, the only way to debug or set breakpoints within the command queue is by means of callbacks, as shown in the following example.
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 });
The example where taken from https://github.com/nightwatchjs/nightwatch/wiki/Understanding-the-Command-Queue.
Except for the execute command, because nightwatch injects the specified script directly into the browser, which will be executed right there. Moreover, chrome only allows one DevTools per page, hence it will try to reopen the DevTools each time a command must be executed.
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.
Source: https://sites.google.com/a/chromium.org/chromedriver/help/devtools-window-keeps-closing
Upvotes: 1