This question already has answers here:
How to pass a variable as an argument to a CasperJS script through the command line?
(5个答案)
5年前关闭。
我正在使用Windows的命令行运行CasperJS,我想知道如何使用命令行来获取用户的输入。
我想在脚本执行过程中向用户询问信息,或者在运行脚本之前传递参数,例如:
现在,我通过命令行运行它,如下所示:
谢谢大家的答复。
(5个答案)
5年前关闭。
我正在使用Windows的命令行运行CasperJS,我想知道如何使用命令行来获取用户的输入。
我想在脚本执行过程中向用户询问信息,或者在运行脚本之前传递参数,例如:
casperjs test test.js my_argument_here
最佳答案
我对此主题进行了更多研究,发现无法在测试器模块内创建自己的Casper对象。
这是我所做的(以防万一有人遇到相同的问题):
我将其包含在我的test.js文件中:
var url = casper.cli.get("url")
现在,我通过命令行运行它,如下所示:
casperjs test test.js --url="http://google.com"
谢谢大家的答复。