Running 'casperjs test' in phantom

倾然丶 夕夏残阳落幕 提交于 2019-12-18 07:04:52

问题


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!


回答1:


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



回答2:


you can also call casperjs test xyz.js

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



来源:https://stackoverflow.com/questions/19857139/running-casperjs-test-in-phantom

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!