【问题标题】:How to import other js files in casperjscasperjs中如何导入其他js文件
【发布时间】:2015-01-29 06:27:54
【问题描述】:

基本上,我已将可重用函数提取到文件“utility.js”中。我想将此文件导入每个 CasperJS 测试脚本。我正在关注文档here

当我尝试让它工作时,我收到以下错误。

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

【问题讨论】:

    标签: javascript testing phantomjs casperjs file-import


    【解决方案1】:

    您还可以在 casperjs 脚本中使用幻像对象。

    尝试将实用程序指定为库路径:

    phantom.libraryPath=[relativePath]
    

    有关更多选项,请参阅 phantom js 文档:http://phantomjs.org/api/phantom/property/library-path.html

    据 casperjs 的作者说

    幻象对象在 casperjs 环境中的任何地方都可用,主要是 因为 casperjs 环境首先是 phantomjs 环境。 https://github.com/n1k0/casperjs/issues/355

    【讨论】:

      猜你喜欢
      • 2016-08-19
      • 1970-01-01
      • 1970-01-01
      • 2022-01-10
      • 2012-10-07
      • 2021-10-04
      • 2022-01-22
      相关资源
      最近更新 更多