Take the 2-minute tour ×

I'm new to casperjs and my desire is to try to test the javascript loaded by certain pages of a web app. I'm using casper.thenOpen to load a page from the web server, but it doesn't in turn load the tags that reference js files. I even checked the web server's access log and sure enough, only the page itself was requested, not the js files.

I would imagine there is built in functionality for doing this, but if I have to do this manually I can live with writing my own utility function for it. But again, being new to casperjs, I'm not sure how I'd go about it - I haven't been able to locate examples that will help me figure this out.

EDIT: Here is what my code looks like. This works if myobject is defined within a script tag, but not if it's defined by an external js file because the external js files aren't loading, as my server's access log confirms. So how to force them to load?

casper.test.begin('my test', function suite(test) {
    casper.start("http://mysite", function() {
        this.test.assertEquals("function", this.page.evaluate(function(){return myobject.myproperty;}));

    casper.run(function() {
share|improve this question
CasperJS is just a wrapper over PhantomJS and PhantomJS loads a webpage as gets loaded in a browser. Thus, ideally it should load the page along with all the scripts, css, images, objects etc.. However, you can force disable loading of images and plugins. This does not stops loading of scripts unless your server prevents it. You can try first with basic website with a small script and test. Also, make sure there is no error in the script loading tag (like the tag is closed etc.) Best of luck! :D –  sudipto Sep 16 '13 at 7:16
Yes, ideally it should, but it isn't. No script errors or anything of that sort. Added code sample to original question. Maybe that'll help illuminate the problem? –  user2778351 Sep 16 '13 at 20:11
OK, I'm not sure what fixed it, but I realized it's working now. I was referencing my object incorrectly which delayed recognizing that the js files (and css and images) started downloading as expected. So unfortunately I can't even really answer my own question! –  user2778351 Sep 16 '13 at 22:14
add comment


Your Answer



Browse other questions tagged or ask your own question.