【发布时间】:2019-04-05 18:30:01
【问题描述】:
所以,我有一个可运行的 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;
实用程序:
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
}
}
}
我认为这与我的噩梦实例没有被导出/导入有关,但不知道该怎么做。
【问题讨论】:
-
npm 包简直是噩梦?
-
是的,nightmare.js 是一个用于网页自动化的 npm 包