testing DOM elements with phantomjs/casperjs

為{幸葍}努か 提交于 2019-12-06 00:04:22

Have you tried any of the waitFor functions. You could try something like this:

casper.test.begin('Main page test', 2, function suite(test) {

    casper.start('http://xxx.yyy.zzz/', function() {
        test.assertTitle('My page name', 'page title is set correctly');
    });

    casper.waitFor(function check() {
        return this.evaluate(function() {
            return $('loading label').is('hidden');
        });
    }, function then() {    // step to execute when check() is ok
        test.assertExists('#tabsListArea', 'tabs area is found');
    }, function timeout() { // step to execute if check has failed
        this.echo("Timeout: page did not load in time...").exit();
    });

    casper.run(function() {
       test.done();
   });
});

You could then play around with the waitTimeout option so you give the page enough time to load. It isn't a perfect solution but it could work in this case.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!