简体   繁体   English

守夜人-使用node.js和Chrome进行调试

[英]nightwatch - debugging with node.js and Chrome

Is there a way to debug nightwatch even within the command chains, or debug the injected code in chrome DevTools? 有没有一种方法可以甚至在命令链中调试夜表,也可以在chrome DevTools中调试注入的代码?

For instance, I want to debug the "window" object: 例如,我要调试“窗口”对象:

在此处输入图片说明

I use chrome Version 59.0.3071.115. 我使用的是Chrome版本59.0.3071.115。 According to ChromeDriver - WebDriver for Chrome the DevTools is always disconnected from ChromeDriver as soon as the DevTools opens. 根据ChromeDriver-适用于ChromeWebDriver的说明,在DevTools打开后,DevTools总是与ChromeDriver断开连接。 Meaning, if I inject the code within the execute command (images) the DevTools will close and I have to reopen it again? 意思是,如果我将代码注入到execute命令(图像)中,DevTools将关闭,我必须再次将其重新打开吗? Meaning, I cannot even debug it in the front end? 意思是说,我什至不能在前端调试它?

Thanks! 谢谢!

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 . 该示例取自https://github.com/nightwatchjs/nightwatch/wiki/Understanding-the-Command-Queue

Except: 除了:

Except for the execute command, because nightwatch injects the specified script directly into the browser, which will be executed right there. 除了execute命令外,因为nightwatch将指定的脚本直接注入浏览器,该脚本将在该浏览器中执行。 Moreover, chrome only allows one DevTools per page, hence it will try to reopen the DevTools each time a command must be executed. 而且,chrome每页只允许一个DevTools,因此每次必须执行命令时,它将尝试重新打开DevTools。

DevTools window keeps closing DevTools窗口保持关闭

This is normal. 这很正常。

When you open the DevTools window, ChromeDriver is automatically disconnected. 当您打开DevTools窗口时,ChromeDriver会自动断开连接。 When ChromeDriver receives a command, if disconnected, it will attempt to close the DevTools window and reconnect. 当ChromeDriver收到命令时,如果断开连接,它将尝试关闭DevTools窗口并重新连接。

Chrome's DevTools only allows one debugger per page. Chrome的DevTools每页只允许一个调试器。 As of 2.x, ChromeDriver is now a DevTools debugging client. 从2.x版本开始,ChromeDriver现在是DevTools调试客户端。 Previous versions of ChromeDriver used a different automation API that is no longer supported in Chrome 29. 先前版本的ChromeDriver使用了另一个自动化API,Chrome 29不再支持该API。

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. 如果您需要检查DevTools中的内容,现在最好的办法就是暂停测试,以使ChromeDriver不会关闭DevTools。 When you are done inspecting things in Chrome, you can unpause your test and ChromeDriver will close the window and continue. 在Chrome中检查完所有内容后,您可以取消暂停测试,ChromeDriver将关闭该窗口并继续。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM