Search code examples
google-chromedebuggingphantomjsremote-debuggingcasperjs

How to remote debug CasperJS with Chrome?


What are the steps to debug CasperJS scripts in Chrome? I'm trying to debug on my windows 8.1.

1) my test c:\temp\googletestin.js have:

debugger;

casper.test.begin('Google search retrieves 10 or more results',3, function suite(test) {

    casper.start("http://www.google.com.br/", function() {
        this.echo(">>Number 1");
        test.assertTitle("Google", "Title home page google");

        casper.echo(">>Number 2");
        test.assertExists('form[action="/search"]', "find form search");

        casper.echo(">>Number 3");
        this.fill('form[action="/search"]', {
            q: "casperjs"
        }, true);

        this.echo(">>Number 4");
        casper.capture('test.png', undefined, {
        format: 'png',
        quality: 75
        });

    })

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

2) open cmd.exe

3) do the command line

>casperjs test c:\temp\googletesting.js --remote-debugger-port=9222 --remote-debugger-autorun=yes

ps: the test running until the end normally

4) open chrome and field that url: http:localhost:9222

5) page is blank

6) open console (f12) and do: __run(); but nothing is happening


Solution

  • In step 3 you need to pass the debugger options into CasperJS and not the script where it would be accessible through casper.cli. You also should not let the script autostart (--remote-debugger-autorun=yes) otherwise it will run before you can debug it. As you correctly stated, you can then open Chrome/Safari and call __run() to trigger the script execution.

    casperjs --remote-debugger-port=9222 test yourScript.js