导出/导入Nightmare.js功能

问题描述 投票:0回答:1

所以,我有一个工作的nightmare.js应用程序,100%工作。我现在处于重构阶段,并希望将我自己制作的自定义函数(使用nightmare.js函数)放入另一个文件中,然后将它们导出/导入到我的主文件中。

函数被调用,但是恶梦函数实际上并不执行或抛出错误。

为什么导入噩梦功能不起作用?

我的主要应用:

const Nightmare = require('nightmare')
const nightmare = Nightmare({
    show: true,
    typeInterval: 1000,
    waitTimeout: 60 * 1000
})

const bot = require('./utils')

nightmare
    .goto(url)
    .then(_ => bot.selectByVal('#myDiv', 'myVal'))
    .then( 'yada yada yada ...')...

module.exports = nightmare;

utils的:

const Nightmare = require('nightmare');
const nightmare = Nightmare();

module.exports = {
    selectByVal: function(el, val) {
        console.log('select' + el + val)
        try {
            return nightmare.select(el, val)
        } catch (e) {
            return e
        }
    }
}

我相信这与我的噩梦实例没有导出/导入有关,但不知道如何做到这一点。

node.js nightmare
1个回答
0
投票

qazxsw poi或qazxsw poi无法访问主应用程序中创建的qazxsw poi。您需要传递参考。

返回一个返回一个对象的函数。

bot

然后在您的主应用程序上,

utils
© www.soinside.com 2019 - 2024. All rights reserved.