Running 'casperjs test' in phantom
Asked Answered
C

2

3

So I have a file running in node which runs a local copy of PhantomJS as below shows:

phantom.casperPath = 'node_modules/casperjs';
phantom.injectJs('node_modules/casperjs/bin/bootstrap.js');
var casper = require('casper').create({
    viewportSize: config.viewportSize
});

casper.test.begin('Runing tests here', 5, function suite(test) {
    // Tests here
});

Without the casper.test.begin() my tests function fine. I have the correct version 1.1.0 which can use this test suite but I get the following error in my console:

CasperError: casper.test property is only available using the `casperjs test` command

The CasperJS docs mentions this too: http://docs.casperjs.org/en/latest/testing.html. My question is how do I run this Casper under this command in the above code so I can use these tests?

Thanks!

Conundrum answered 8/11, 2013 at 10:47 Comment(0)
I
7

CasperError: casper.test property is only available using the casperjs test command

problem solved.

You have to include this line at the top of your script in your xyz.js, so that the .test property becomes true;

phantom.casperTest = true;

Then you should have no problem Launching from the terminal:

casperjs xyz.js
Inductee answered 11/12, 2013 at 6:13 Comment(1)
In my reading of bootstrap.js, I see the setting of casperTest, but quite a number of things are done. This answer was not sufficient in my use case of running capserjs from a phantomjs REPL.Fragmental
A
0

you can also call casperjs test xyz.js

For more info, check the doco here : http://docs.casperjs.org/en/latest/testing.html

Altruist answered 24/7, 2017 at 5:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.