【发布时间】:2015-10-02 21:24:02
【问题描述】:
casper.on("page.initialized", function(casp){
this.echo("Initialized...");
casper.evaluate(function(){ window.sessionStorage.setItem('authorization','xxxxxxx');
window.sessionStorage.setItem('_USER','xxxxx');
window.sessionStorage.setItem('USERNAME','xxxxx');
window.sessionStorage.setItem('INTERNAL','xxxx');
});
};
casper.test.begin('1: Asserting casperjs is working', 2, function suite(test) {
test.assertEquals(true, true);
test.assert(true);
test.done();
});
casper.test.begin('starting at /', 5, function suite(test
var starting = Date.now();
casper.start();
casper.open("xxxxx",function() {
test.assertHttpStatus(200);
var session = this.evaluate(function(){
return JSON.stringify(window.sessionStorage);
});
this.echo("SESSION: ", session);
});
casper.then(function(){
this.wait(10000, function(){this.echo("WAITED!");});
this.echo(this.getHTML('body'));
try{
casper.waitFor(function check() {
return this.evaluate(function() {
var quotes = document.getElementById('quoteBody').children.length > 1;
this.echo("QUOTES", quotes);
return true;
});
}, function then() {
// ending timer
var ending = Date.now();
var totalt = (ending - start) / 3600;
test.assertFalsy(function(){
return totalt >= 10.0;
}, "loading asserting total time passed");
this.echo("total time: ", totalt);
// tests
test.assertEval(function(){
return document.querySelectorAll('#quotesBody tr').length > 1;
});
//this.echo(this.getHTML('body'));
this.assertTitle("xxxxx", "title match");
});
} catch (e){
this.echo(e);
}
});
casper.run(function() {
test.done();
});
});
我尝试将test.done() 包裹在超时中,但我无法通过无休止的Unsafe JavaScript attempt to access frame with URL about:blank from frame with URL... 警告。 document.getElementById('quoteBody').children.length > 1; 在浏览器中工作,但不返回 true 并触发 waitTimeout 事件。发出此事件后,我才收到警告。我尝试等待比10000 更长的时间来加载无济于事。我能够从@Artjom B 那里得到一些很好的建议来让我的脚本开始运行,但是这个看似常年存在的幻影错误给我的日志增加了噪音,如果返回 falsy,waitFor 不应出现任何Unsafe 错误。
编辑
如果警告没有完全污染我的输出,我想我可以修复我的脚本。我试过 web-security=no flags - 没用。从 1.9.8 降级到 phantom 1.9.2?我知道 1.9.8 有点问题,很多人都遇到了这个问题。我现在更关心如何摆脱噪音。
【问题讨论】:
-
请忽略“不安全...”警告。它们在退出期间打印,对您的脚本没有任何影响。相反,您应该明确脚本的问题所在。显示一些输出,描述行为并说明需要发生的事情。