[英]How to import other javascript module in PhantomJS or CasperJS
[英]How to import other js files in casperjs
基本上,我已经将可重复使用的功能提取到文件“ utility.js”中。我想将此文件导入每个CasperJS测试脚本中。我关注此处的文档
当我尝试使其正常工作时,出现以下错误。
'undefined'不是一个函数
文件夹结构是这样的
utility.js
test1.js
test2.js
测试文件具有上述文档建议的以下代码
var require = patchRequire(require);
var helper = require('utility');
然后按如下方式访问Utility.js中的函数helper.fn_do_something()
我尝试使用casperJS提供的其他方法,例如
casper.options.clientscript = [relativepath];
但这无济于事,我遇到了同样的错误。
我正在使用PhantomJS 1.9.8。
您还可以在casperjs脚本中使用幻像对象。
尝试将实用程序指定为库路径:
phantom.libraryPath=[relativePath]
有关更多选项,请参见phantom js文档: http : //phantomjs.org/api/phantom/property/library-path.html
据casperjs的作者
phantom对象可在casperjs env中的任何位置使用,主要是因为casperjs环境最初是phantomjs环境。 https://github.com/n1k0/casperjs/issues/355
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.