HuddleEng / PhantomCSS

Visual/CSS regression testing with PhantomJS
MIT License
4.72k stars 259 forks source link

Running PhantonCSS test after javascipt run on the page. #186

Closed ruxiang05 closed 7 years ago

ruxiang05 commented 7 years ago

I am having a carousel with two left/right control buttons on the side. However, when I run the test they don't appear. I believe this is because the javascript hasn't run on the page. Is there any way I can test after the js run?

jamescryer commented 7 years ago

Use CasperJS's waitFor methods such as http://docs.casperjs.org/en/latest/modules/casper.html#waitforselector

var selector = '.carousel-control-left';
casper.waitForSelector(selector , function() {
   phantomcss.screenshot(selector , 'carousel-control-left');
});

It would also be worth checking that your code isn't throwing errors (maybe because you are using a feature of JavaScript that is not supported by PhantomJS) http://docs.casperjs.org/en/latest/events-filters.html

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