UPDATE: I found the solution and I forgot to add
var casper = require('casper').create();
on the top.
The original question: I installed phantom js 1.9.2 and casper js 1.0.3. Additionally I copy and pasted the follwing sample script directly from the casper js tutorial page:
casper.start('/', function() {
var url = '/';
this.download(url, 'google_pany.html');
});
casper.run(function() {
this.echo('Done.').exit();
});
This is the output on my mac os lion:
bin Tom$ ./casperjs ../site_loader.js
2013-11-26 18:53:20.375 phantomjs[2136:130b] *** WARNING: Method userSpaceScaleFactor in class NSView is deprecated on 10.7 and later. It should not be used in new applications. Use convertRectToBacking: instead.
ReferenceError: Can't find variable: casper
../site_loader.js:1
Hint: you may want to use the `casperjs test` mand.
^C
I have to manually cancel it otherwise it will never stop. However running the suggested mand yields:
bin Tom$ ./casperjs test
2013-11-26 18:54:01.504 phantomjs[2137:130b] *** WARNING: Method userSpaceScaleFactor in class NSView is deprecated on 10.7 and later. It should not be used in new applications. Use convertRectToBacking: instead.
No test path passed, exiting.
What is not correct here?
UPDATE: I found the solution and I forgot to add
var casper = require('casper').create();
on the top.
The original question: I installed phantom js 1.9.2 and casper js 1.0.3. Additionally I copy and pasted the follwing sample script directly from the casper js tutorial page:
casper.start('http://www.google.fr/', function() {
var url = 'http://www.google.fr/intl/fr/about/corporate/pany/';
this.download(url, 'google_pany.html');
});
casper.run(function() {
this.echo('Done.').exit();
});
This is the output on my mac os lion:
bin Tom$ ./casperjs ../site_loader.js
2013-11-26 18:53:20.375 phantomjs[2136:130b] *** WARNING: Method userSpaceScaleFactor in class NSView is deprecated on 10.7 and later. It should not be used in new applications. Use convertRectToBacking: instead.
ReferenceError: Can't find variable: casper
../site_loader.js:1
Hint: you may want to use the `casperjs test` mand.
^C
I have to manually cancel it otherwise it will never stop. However running the suggested mand yields:
bin Tom$ ./casperjs test
2013-11-26 18:54:01.504 phantomjs[2137:130b] *** WARNING: Method userSpaceScaleFactor in class NSView is deprecated on 10.7 and later. It should not be used in new applications. Use convertRectToBacking: instead.
No test path passed, exiting.
What is not correct here?
Share Improve this question edited Nov 26, 2013 at 18:00 toom asked Nov 26, 2013 at 17:55 toomtoom 13.4k27 gold badges95 silver badges137 bronze badges 1-
The example is for version 1.1.0-dev If you update, you will need to remove the
var casper = require('casper').create();
, otherwise the program won't exit because thecasperjs test
mand will provide that call – hexid Commented Nov 26, 2013 at 18:03
1 Answer
Reset to default 4Very first of all, you need to create a casper instance to work with, then everything you have written will work!
// sample.js
var casper = require('casper').create();
casper.start('http://www.google.fr/', function() {
var url = 'http://www.google.fr/intl/fr/about/corporate/pany/';
this.download(url, 'google_pany.html');
});
casper.run(function() {
this.echo('Done.').exit();
});
Output:
C:\Users\hello\Desktop>caperjs sample.js
Done.
C:\Users\hello\Desktop>ls -alt
-rwx------ hello mkpasswd 91 Nov 28 09:11 google_pany.html
...