我正在寻找一种方法来读取记录到firebug控制台的最新命令.
例如,我可以做一些事情
console.debug('The most current request URI is /sweatsocks');
然后可以使用另一段(伪)代码
if (mostRecentConsoleEntry().endsWith('/sweatsocks')) { // do some stuff }
作为调试语句的上下文将在测试中的代码中,并且控制台检查将在selenium脚本内完成.这将让我观察深埋在js函数中的信息以及在运行时构建的东西.
您可以覆盖该console.log
函数以添加所需的任何额外功能.
var oldLog = console.log; var lastLog; console.log = function () { // do whatever you need to do here: store the logs into a different variable, etc // eg: lastLog = arguments; // then call the regular log command oldLog.apply(console, arguments); };
这不是最防弹的解决方案,因为console
允许printf样式语法:
console.log("%d + %d = %s", 1, 3, "four");
......但它可能是你的开始.