Files
puppeteerjs/main.js
T
2022-09-07 21:24:07 +02:00

60 lines
1.7 KiB
JavaScript

const {_android: android} = require('playwright');
const ExcelUtil = require("./src/excel/ExcelUtil");
const CommandorPage = require("./src/workers/CommandorPage");
const MongoManager = require("./src/workers/mongo_manager");
function delay(delayInms) {
return new Promise(resolve => {
setTimeout(() => {
resolve(2);
}, delayInms);
});
}
const mongoManager = new MongoManager();
let excelUtil = new ExcelUtil();
let contactList = excelUtil.readContacts();
// Connect to the device.
async function startBook(contactPojo, device) {
console.log(`Model: ${device.model()}`);
console.log(`Serial: ${device.serial()}`);
let commandor = new CommandorPage(contactPojo, device, mongoManager);
//read contacts form excel
return await commandor.loadPage();
}
mongoManager.connect().then(r => console.log("mongo connected"))
async function printFiles() {
let devices = await android.devices();
await contactList.reduce(async (promise, contactPojo) => {
// This line will wait for the last async function to finish.
// The first iteration uses an already resolved Promise
// so, it will immediately continue.
await promise;
const contents = await startBook(contactPojo, devices[0]);
console.log(contents);
}, Promise.resolve());
}
(async () => {
printFiles()
})()
// android.devices().then((device_list) => {
// contactList.forEach((contactPojo) => {
// device_list.forEach((device) => {
// (async () => {
// await startBook(contactPojo, device)
// })()
// }
// )
// }
// )
// })