在javascript中阅读firebug控制台 [英] reading the firebug console in javascript
问题描述
我正在寻找一种方法来读取记录到firebug控制台的最新命令。
I'm looking for a way to read the most recent command that was logged to the firebug console.
例如,我可以做一些事情
For example, I could have something that does
console.debug('The most current request URI is /sweatsocks');
然后另一条(伪)代码可以
And then another piece of (pseudo)code could then
if (mostRecentConsoleEntry().endsWith('/sweatsocks')) {
// do some stuff
}
作为调试语句的上下文将出现在被测试的代码中,控制台检查将在selenium脚本中完成。这将让我观察深埋在js函数中的信息以及在运行时构建的东西。
The context being the debug statement would be in the code under test, and the console checking would be done inside a selenium script. This would let me observe information buried deep in js functions as well as stuff that is built at runtime.
推荐答案
你可以覆盖 console.log
添加所需的额外功能的函数。
You could overwrite the console.log
function to add whatever extra functionality you need.
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样式语法:
This won't be the most bulletproof solution, since console
allows printf style syntax:
console.log("%d + %d = %s", 1, 3, "four");
...但这可能是你的开始。
...but it's probably a start for you.
这篇关于在javascript中阅读firebug控制台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!