How use --config with CasperJS

被刻印的时光 ゝ 提交于 2019-12-22 18:39:12

问题


I've read the Casper documentation and they say that ALL PhantonJS cli options is available on CasperJS but I am trying to use --config=/path/to/config.json and is not working.

Is there a way to fix this or do something similar since I don't want to be editing the configs on terminal.

casperjs --config=config.json test.js

My config.json file:

{
    "load-images" : false
}

My test.js file:

var casper = require('casper').create();

casper.start('http://www.example.com/', function(){
    this.capture('image.png');
})

.run();

That code above is loading the images. Of course this is a simple example and what I want to is manage lots of options inside the config file.

Thanks


回答1:


This issue shows the inconsistencies:

--disk-cache => diskCacheEnabled
--load-images => autoLoadImages
--local-storage-path => offlineStoragePath
--local-storage-quota => offlineStorageDefaultQuota
--local-to-remote-url-access => localToRemoteUrlAccessEnabled
--web-security => webSecurityEnabled
--debug => printDebugMessages

But autoLoadImages is broken. I just verified that webSecurityEnabled works as expected.

PhantomJS version 1.9.7.


A workaround would be to include the following code in every test file:

if (casper.cli.has("config2")) {
    var config = require(casper.cli.get("config2"));
    casper.options.pageSettings.loadImages = config.autoLoadImages;
}

and call it with the other command line flag

casperjs --config=config.json --config2=config.json test.js


来源:https://stackoverflow.com/questions/25310931/how-use-config-with-casperjs

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