16

How can I inspect an object in a casperjs script ?

I tried console.log(arguments) but it only prints [object Arguments] or [object Object].

I would like to expect something like: { 'firstparam': 'value' ... }

Like in the Javascript console or in Node.js...

Maybe it's a Phantomjs question, I'm not sure...

Charles
  • 11,367
  • 10
  • 77
  • 114

2 Answers2

16

I think I found it: http://docs.casperjs.org/en/latest/debugging.html#dump-serialized-values-to-the-console

var utils = require('utils');

utils.dump({
    foo: {
        bar: 42
    },
});
Christoph
  • 1,310
  • 16
  • 28
Charles
  • 11,367
  • 10
  • 77
  • 114
  • I wonder how to use the phantom.js one, I know there must be something because when running on console (interactively) `var a = {a:[1]}; a` prints neatly – Fabiano Soriani Oct 21 '12 at 04:02
  • 12
    Just use standard `JSON.stringify()` method: https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/JSON/stringify – NiKo Nov 10 '12 at 10:21
1

JSON.stringify for a simple string read, e.g.

casper.test.comment(JSON.stringify(object));
klidifia
  • 1,415
  • 1
  • 12
  • 18