如何在CasperJS中使用--config [英] How use --config with CasperJS

查看:84
本文介绍了如何在CasperJS中使用--config的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经阅读了Casper文档,并且他们说CasperJS上有所有PhantonJS cli选项,但我正在尝试使用--config = / path / to / config.json并且无效。

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文件:

My config.json file:

{
    "load-images" : false
}

我的test.js文件:

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.

谢谢

推荐答案

此问题显示不一致之处:


--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

autoLoadImages 已损坏。我刚验证 webSecurityEnabled 按预期工作。

PhantomJS版本1.9.7。

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

这篇关于如何在CasperJS中使用--config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆