diff --git a/src/commands/texei/cpqsettings/set.ts b/src/commands/texei/cpqsettings/set.ts index 79b2c31..768d0e0 100644 --- a/src/commands/texei/cpqsettings/set.ts +++ b/src/commands/texei/cpqsettings/set.ts @@ -73,13 +73,13 @@ export default class Set extends SfCommand { }); const page = await browser.newPage(); + const waitForNavigationOptions: puppeteer.WaitForOptions = { waitUntil: ['domcontentloaded', 'networkidle2'] }; + this.log(`Logging in to instance ${instanceUrl}`); - await page.goto(frontdoorUrl, { waitUntil: ['domcontentloaded', 'networkidle0'] }); - const navigationPromise = page.waitForNavigation(); + await page.goto(frontdoorUrl, waitForNavigationOptions); this.log(`Navigating to CPQ Settings Page ${cpqSettingsUrl}`); - await page.goto(`${cpqSettingsUrl}`); - await navigationPromise; + await page.goto(`${cpqSettingsUrl}`, waitForNavigationOptions); // Looking for all elements to update // Iterating on tabs @@ -94,7 +94,6 @@ export default class Set extends SfCommand { // Clicking on tab const tab = tabs[0].asElement() as ElementHandle; await tab.click(); - await navigationPromise; // For all fields on tab for (const key of Object.keys(cpqSettings[tabKey])) { @@ -130,7 +129,7 @@ export default class Set extends SfCommand { ); await targetInput?.click(); - await navigationPromise; + await page.waitForNavigation(); this.spinner.stop(`Checkbox Value updated from ${currentValue} to ${cpqSettings[tabKey][key]}`); } else { @@ -195,8 +194,8 @@ export default class Set extends SfCommand { this.spinner.start('Saving changes', undefined, { stdout: true }); const saveButton = await page.$("#page\\:form input[value='Save']"); await saveButton?.click(); - await navigationPromise; - // Timeout to wait for save, there should be a better way to do it + await page.waitForNavigation(); + await new Promise((r) => setTimeout(r, 3000)); // Look for errors diff --git a/src/commands/texei/org/contractfieldhistory/fix.ts b/src/commands/texei/org/contractfieldhistory/fix.ts index ba9e9f0..ec698a8 100644 --- a/src/commands/texei/org/contractfieldhistory/fix.ts +++ b/src/commands/texei/org/contractfieldhistory/fix.ts @@ -54,21 +54,20 @@ export default class Fix extends SfCommand { headless: !(process.env.BROWSER_DEBUG === 'true'), }); const page = await browser.newPage(); + const waitForNavigationOptions: puppeteer.WaitForOptions = { waitUntil: ['domcontentloaded', 'networkidle2'] }; + await page.goto( `${instanceUrl}/secur/frontdoor.jsp?sid=${ flags['target-org'].getConnection(flags['api-version']).accessToken }&startURL=${encodeURIComponent(POST_LOGIN_PATH)}`, - { waitUntil: ['domcontentloaded', 'networkidle0'] } + waitForNavigationOptions ); - const navigationPromise = page.waitForNavigation(); - this.debug('DEBUG Opening Contract Field History Tracking page'); - await page.goto(`${instanceUrl}/ui/setup/layout/FieldHistoryTracking?pEntity=Contract`); - await navigationPromise; + await page.goto(`${instanceUrl}/ui/setup/layout/FieldHistoryTracking?pEntity=Contract`, waitForNavigationOptions); this.debug("DEBUG Clicking 'Save' button"); await page.click('table > tbody > tr > #topButtonRow > .btn:nth-child(1)'); - await navigationPromise; + await page.waitForNavigation(waitForNavigationOptions); this.debug('DEBUG Closing browser'); await browser.close();