我试图用node.js
编写一个性能工具,这样我就可以自动执行它,并将结果存储在MySQL
中。该工具应该收集浏览器加载特定网页所用的时间。我使用HttpWatch测量性能,结果以秒显示。使用的浏览器是Firefox。 下面是我使用一段脚本来运行性能测试:node.js循环迭代后崩溃
var MyUrls = [
"http://google.com",
"http://yahoo.com"
];
try {
var win32ole = require('win32ole');
var control = win32ole.client.Dispatch('HttpWatch.Controller');
var plugin = control.Firefox.New();
for (var i=0; i < MyUrls.length; i++) {
var url = MyUrls[i];
console.log(url);
for(var j=0; j < 14; j++) {
// Start Recording HTTP traffic
plugin.Log.EnableFilter(false);
// Clear Cache and cookier before each test
plugin.ClearCache();
plugin.ClearAllCookies();
plugin.ClearSessionCookies();
plugin.Record();
// Goto to the URL and wait for the page to be loaded
plugin.GotoURL(url);
control.Wait(plugin, -1);
// Stop recording HTTP
plugin.Stop();
if (plugin.Log.Pages.Count != 0)
{
// Display summary statistics for page
var summary = plugin.Log.Pages(0).Entries.Summary;
console.log(summary.Time);
}
}
}
plugin.CloseBrowser();
} catch(e) {
console.log('*** exception cached ***\n' + e);
}
内循环的第二次迭代后,我发现了以下错误:
C:\xampp\htdocs\test\browser-perf>node FF-load-navigation.js
http://localhost/NFC-performance/Bing.htm
[Number (VT_R8 or VT_I8 bug?)]
2.718
[Number (VT_R8 or VT_I8 bug?)]
2.718
OLE error: [EnableFilter] -2147352570 [EnableFilter] IDispatch::GetIDsOfNames Au
toWrap() failed
让别人之前看过这个?你可以帮我吗?
您正在使用的Firefox“插件”的API文档在哪里?我怀疑像ClearCache和ClearCookies这样的方法是同步的(即在操作完成之前阻塞执行)。如果它们是异步的,则需要为它们指定回调。 https://github.com/idobatter/node-win32ole说“异步,非阻塞win32ole绑定” - 我的预期。 – 2013-05-08 11:20:20
这很古怪,WIN32OLE的自述说,它应该是非阻塞的,但示例显示各种功能只是以同步的方式。这就像自述文件直接躺在你的脸上一样。 – 2013-05-08 11:23:59