casperjs waitfor神秘地表现

时间:2013-11-17 17:30:55

标签: casperjs

我正在尝试测试流程

1.Ajax Request      > Loader is visible

2.Response Received > a.Loader is hidden
                      b.Redirect to another page(where a interstitial is visible)

白色使用casperJS测试它我使用waitFor方法,就像这样。

   casper.waitFor(function check() {
        return this.evaluate(function() {
            return $("#loader").is(":hidden");
        });
    }, function then() {
        this.test.pass("Ajax request");
        this.waitDone();
    }, function timeout() { // step to execute if check has failed
        this.echo("Timeout: page did not load in time...").exit();
    },4000);

即使在check中传递了条件,但在页面未被重定向之前不会执行then(读取流程,我正在尝试测试)并且测试套件赢了“转到下一步。

我在这里缺少什么吗?

1 个答案:

答案 0 :(得分:1)

确保您的参考'this'位于casper块中:

casper.then(function() {
    this.waitFor(function check() {

可能的快速修复,无需了解更多细节。传递jQuery变量进行评估。

this.evaluate(function($) {

您也可以尝试:

casper.waitWhileVisible('#loader', function() {
    // executes when #loader is hidden
});

文档位于:CasperJS waitWhileVisible