我有一个不工作的 CasperJS JQuery 事件处理的简单示例,我从未见过
* page event received***********
打印。相反,我看到以下日志
[error] [phantom] Wait timeout of 20000ms expired, exiting.
Wait timeout of 20000ms expired, exiting.
我错过了什么吗?
我正在使用 CasperJS 1.0.2
事件测试.html
<!doctype html>
<html lang="en">
<head>
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
</head>
<body>
<div>Event test for CasperJS</div>
<script>
setTimeout(function(){ $(document).trigger("pageRendered");}, 5000)
/*
$(document).on("pageRendered", function(){
//window.__pageRendered_triggered__ = true;
//alert("page loaded triggered");
console.log("page loaded triggered");
});*/
</script>
</body>
</html>
事件测试.js
var casper = require('casper').create({
verbose: true,
logLevel: "debug",
viewportSize: {
width: 1024, //970,
height: 768 // 3074
},
waitTimeout: 10000
});
casper.start('http://localhost/jqueryev.html', function() {});
casper.waitFor(function () {
return this.evaluate(function testForJQuery() {
return typeof(window.$) !== 'undefined';
});
}, function then() {
this.echo('* [event] jquery loaded');
});
casper.evaluate(function() {
// this fails...
$(document).on('pageRendered', function() {
window.__pageRendered_triggered__ = true;
});
});
casper.waitFor(function() {
return this.evaluate(function() {
return window.__pageRendered_triggered__ === true;
})===true;
}, function then() {
console.log("* page event received***********");
});
casper.run();