2014-05-22 21 views
0

所以这里的另一个麻烦。我有一个脚本加载SVG,并等待它出现随机失败。有时幻象留卡装载SVG(即使有waitTimeout在2分钟,所以问题不在这里,我认为)。脚本:http:// r.ccmbg.com/js.php?m=highchart=...CasperJS/PhantomJS:waitForSelector( 'SVG') - > SVG有时不出现

我仍然可以加载页面X次循环中,等待SVG出现,但我更喜欢另一种解决方案。如果你有一个想法,我全是耳朵。

简单的例子:

casper.test.begin('\n********* Navigation on directories : ***********', 8,{ 
setUp: function(test) { 
    //setLevel("normal"); 
}, 

tearDown: function(test) { 
    //getJSON(); 
}, 

test: function(test){ 
    "use strict"; 
    casper.start() 
    .thenOpen('http://www.linternaute.com/voyage/climat/paris/ville-75056/2013-2008') 
    .waitForResource(/m=highcharts&/, function(){ 
     this.waitForSelector('svg',function(){ 
      this.test.assertExists("tspan"); 
     }); 
    })  
    .waitForUrl(/2008/, function(){ 
     this.test.assertSelectorHasText("h2", "maximales"); 
     this.test.assertSelectorHasText("h2", "minimales"); 
     this.test.assertSelectorHasText("h2", "Paris"); 
     this.test.assertSelectorHasText("h2", "Le soleil"); 
     this.test.assertSelectorHasText("h2", "La pluie"); 
     this.test.assertExists("div.marB20"); 
     this.test.assertNotEquals(this.fetchText("div.marB20 > table > thead > tr > th"), " ", "Table first data not empty"); 
    }) 
    .run(function() { 
     this.test.comment('--- Done ---\n'); 
     test.done(); 
    }); 
} 
}); 
+1

这也无法在Chrome,所以没有什么可以做。您在页面上发现错误,有时间修复它。 :)在控制台中的错误消息是'资源解释为图像,但与MIME类型application/x-javascript:“http://r.ccmbg.com/js.php?m = highcharts&v = 201310021033'传输... –

回答

0

好吧,当我不知道所谓的脚本或使用的API(所以我不能调试自己),我只是检查的ressource现在。

this.waitForResource(/js\.php\?m=highcharts&v/, function(){ 
    this.test.pass("ressource received (js -> API highcharts)"); 
}); 

不要忘记这个事件找回页文档的错误:

casper.on("page.error", function(msg, trace) { 
    this.echo("Page Error: " + msg, "ERROR"); 
}); 

enter image description here