diff --git a/sync-orders.js b/sync-orders.js index b2604d2..f473d0e 100644 --- a/sync-orders.js +++ b/sync-orders.js @@ -10,9 +10,10 @@ const dotenv = require("dotenv").config({ path: __dirname + "/.env" }); const utils = require("./utils"); (async function () { - console.log(`===========< STARTED ${luxon.DateTime.now()} >=========`); + const screenshotDirectory = path.join(__dirname, "screenshots"); + /** * loading config data */ @@ -118,11 +119,23 @@ const utils = require("./utils"); if (element) { await element.click(); console.log("Clicked on the Request Report btn"); - await page.screenshot({ path: `${luxon.DateTime.now().toMillis()}.png` }); + + // take screenshot + let screenshotPath = path.join( + screenshotDirectory, + `${luxon.DateTime.now().toMillis()}.png` + ); + await page.screenshot({ path: screenshotPath, fullPage: true }); // wait 10 secs await new Promise((resolve) => setTimeout(resolve, 10 * 1000)); - await page.screenshot({ path: `${luxon.DateTime.now().toMillis()}.png` }); + + // take screenshot + screenshotPath = path.join( + screenshotDirectory, + `${luxon.DateTime.now().toMillis()}.png` + ); + await page.screenshot({ path: screenshotPath, fullPage: true }); const confirmBtnSelector = "div._3yOxLjm0._2pgGmJ7w._1eT_m6dA"; const confirmBtnElement = await page.$(confirmBtnSelector); @@ -134,7 +147,13 @@ const utils = require("./utils"); // wait for 3 seconds then reload page await new Promise((resolve) => setTimeout(resolve, 3 * 1000)); - await page.screenshot({ path: `${luxon.DateTime.now().toMillis()}.png` }); + // take screenshot + screenshotPath = path.join( + screenshotDirectory, + `${luxon.DateTime.now().toMillis()}.png` + ); + await page.screenshot({ path: screenshotPath, fullPage: true }); + // wait for 3 mins for request to be processed await new Promise((resolve) => setTimeout(resolve, 3 * 60 * 1000)); } @@ -142,7 +161,13 @@ const utils = require("./utils"); console.log(" Request Btn doest exists"); } - await page.screenshot({ path: `${luxon.DateTime.now().toMillis()}.png` }); + // take screenshot + var screenshotPath = path.join( + screenshotDirectory, + `${luxon.DateTime.now().toMillis()}.png` + ); + await page.screenshot({ path: screenshotPath, fullPage: true }); + // download latest report await page.waitForSelector("div._2zs6hel0"); @@ -161,8 +186,12 @@ const utils = require("./utils"); generateTheDownloadPath(page, downloadFolderPath); console.log("Clicking On download Button"); await new Promise((resolve) => setTimeout(resolve, 10 * 1000)); - await page.screenshot({ path: `${luxon.DateTime.now().toMillis()}.png` }); - + // take screenshot + var screenshotPath = path.join( + screenshotDirectory, + `${luxon.DateTime.now().toMillis()}.png` + ); + await page.screenshot({ path: screenshotPath, fullPage: true }); await divs[0].click(); }