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

标签 node.js selenium debugging visual-studio-code nightwatch.js

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

例如,我想调试“window”对象:

enter image description here

我使用 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/

相关文章:

javascript - 获取和处理数组的 Promise

javascript - 使用 NPM 模块调用 API 'got'

ruby-on-rails - Rails3 Google Maps 使用 selenium 进行测试

c# - .Net 应用程序中的 native 线程

调试Google云消息推送消息

javascript - 带有 MySQL 句柄的 Node.js REST 重新连接

javascript - 通过 Maven 安装 NodeJS

java - 使用 selenium 进行 Maven 范围测试

selenium - 如何在chromedriver中关闭w3c以解决错误未知命令:在W3C中无法调用非W3C标准命令

c# - 为调试目的获取 "critical"机器信息的库?