Я работаю над проектом, в котором все мои файлы указаны в объектной нотации json, я объявил функцию asyn c для одного объекта, и я хочу экспортировать эту функцию из указанного файла c в другой файл. Файл называется test2. js
с кодом как: -
const puppeteer = require('puppeteer')
const test={
browser:null,
page:null,
initial:async () => {
test.browser = await puppeteer.launch({headless:false});
test.page = await test.browser.newPage();
await test.page.goto('https://www.safari.com/');
// await page.screenshot({path: 'example.png'});
async function dostuff(){
let h1;
try{
h1=await test.page.evaluate(()=>{
let h = document.querySelector('h1').innerText;
return {
h
}
});
let heading = h1.h
return heading;
}catch(err){
return `Sorry the value is not been permited`
}
}
//const h = Promise.resolve(dostuff()).then(head =>console.log(head))
//this is working fine
// Promise.resolve(dostuff()).then(head =>console.log(head))
await dostuff()
},
}
module.exports = test //Here I don't kind of know how to call the function as with module.exports.dostuff = this.dostuff is also not working ...
Я хочу вызвать эту функцию во втором файле с именем test_result. js
что похоже на:
const helper = require('./test2')
async function node(){
await helper.initial()
await Promise.resolve(helper.dostuff()).then(head =>console.log(head))
}
node()
Ошибка в коде во время выполнения: «helper.dostuff» не является функцией
Любые идеи о том, как запустить код, чтобы получить данные из элемента в указанное время или при запуске