Running 'casperjs test' in phantom

2019-01-26 20:46发布

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!

2条回答
Summer. ? 凉城
2楼-- · 2019-01-26 21:30

you can also call casperjs test xyz.js

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

查看更多
我想做一个坏孩纸
3楼-- · 2019-01-26 21:34

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
查看更多
登录 后发表回答