Skip to content

Commit d6ee9ea

Browse files
Merge pull request #177 from alanjaouen/master
Fix wait in pupeteer commands
2 parents cd36292 + 8ecefc0 commit d6ee9ea

File tree

2 files changed

+12
-14
lines changed
  • src/commands/texei

2 files changed

+12
-14
lines changed

src/commands/texei/cpqsettings/set.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ export default class Set extends SfCommand<CpqSettingsSetResult> {
7373
});
7474
const page = await browser.newPage();
7575

76+
const waitForNavigationOptions: puppeteer.WaitForOptions = { waitUntil: ['domcontentloaded', 'networkidle2'] };
77+
7678
this.log(`Logging in to instance ${instanceUrl}`);
77-
await page.goto(frontdoorUrl, { waitUntil: ['domcontentloaded', 'networkidle0'] });
78-
const navigationPromise = page.waitForNavigation();
79+
await page.goto(frontdoorUrl, waitForNavigationOptions);
7980

8081
this.log(`Navigating to CPQ Settings Page ${cpqSettingsUrl}`);
81-
await page.goto(`${cpqSettingsUrl}`);
82-
await navigationPromise;
82+
await page.goto(`${cpqSettingsUrl}`, waitForNavigationOptions);
8383

8484
// Looking for all elements to update
8585
// Iterating on tabs
@@ -94,7 +94,6 @@ export default class Set extends SfCommand<CpqSettingsSetResult> {
9494
// Clicking on tab
9595
const tab = tabs[0].asElement() as ElementHandle<Element>;
9696
await tab.click();
97-
await navigationPromise;
9897

9998
// For all fields on tab
10099
for (const key of Object.keys(cpqSettings[tabKey])) {
@@ -130,7 +129,7 @@ export default class Set extends SfCommand<CpqSettingsSetResult> {
130129
);
131130

132131
await targetInput?.click();
133-
await navigationPromise;
132+
await page.waitForNavigation();
134133

135134
this.spinner.stop(`Checkbox Value updated from ${currentValue} to ${cpqSettings[tabKey][key]}`);
136135
} else {
@@ -195,8 +194,8 @@ export default class Set extends SfCommand<CpqSettingsSetResult> {
195194
this.spinner.start('Saving changes', undefined, { stdout: true });
196195
const saveButton = await page.$("#page\\:form input[value='Save']");
197196
await saveButton?.click();
198-
await navigationPromise;
199-
// Timeout to wait for save, there should be a better way to do it
197+
await page.waitForNavigation();
198+
200199
await new Promise((r) => setTimeout(r, 3000));
201200

202201
// Look for errors

src/commands/texei/org/contractfieldhistory/fix.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,21 +54,20 @@ export default class Fix extends SfCommand<OrgContractFieldHistoryResult> {
5454
headless: !(process.env.BROWSER_DEBUG === 'true'),
5555
});
5656
const page = await browser.newPage();
57+
const waitForNavigationOptions: puppeteer.WaitForOptions = { waitUntil: ['domcontentloaded', 'networkidle2'] };
58+
5759
await page.goto(
5860
`${instanceUrl}/secur/frontdoor.jsp?sid=${
5961
flags['target-org'].getConnection(flags['api-version']).accessToken
6062
}&startURL=${encodeURIComponent(POST_LOGIN_PATH)}`,
61-
{ waitUntil: ['domcontentloaded', 'networkidle0'] }
63+
waitForNavigationOptions
6264
);
63-
const navigationPromise = page.waitForNavigation();
64-
6565
this.debug('DEBUG Opening Contract Field History Tracking page');
66-
await page.goto(`${instanceUrl}/ui/setup/layout/FieldHistoryTracking?pEntity=Contract`);
67-
await navigationPromise;
66+
await page.goto(`${instanceUrl}/ui/setup/layout/FieldHistoryTracking?pEntity=Contract`, waitForNavigationOptions);
6867

6968
this.debug("DEBUG Clicking 'Save' button");
7069
await page.click('table > tbody > tr > #topButtonRow > .btn:nth-child(1)');
71-
await navigationPromise;
70+
await page.waitForNavigation(waitForNavigationOptions);
7271

7372
this.debug('DEBUG Closing browser');
7473
await browser.close();

0 commit comments

Comments
 (0)