Skip to content

Commit

Permalink
Merge pull request #177 from alanjaouen/master
Browse files Browse the repository at this point in the history
Fix wait in pupeteer commands
  • Loading branch information
FabienTaillon authored Oct 21, 2024
2 parents cd36292 + 8ecefc0 commit d6ee9ea
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 14 deletions.
15 changes: 7 additions & 8 deletions src/commands/texei/cpqsettings/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,13 @@ export default class Set extends SfCommand<CpqSettingsSetResult> {
});
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
Expand All @@ -94,7 +94,6 @@ export default class Set extends SfCommand<CpqSettingsSetResult> {
// Clicking on tab
const tab = tabs[0].asElement() as ElementHandle<Element>;
await tab.click();
await navigationPromise;

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

await targetInput?.click();
await navigationPromise;
await page.waitForNavigation();

this.spinner.stop(`Checkbox Value updated from ${currentValue} to ${cpqSettings[tabKey][key]}`);
} else {
Expand Down Expand Up @@ -195,8 +194,8 @@ export default class Set extends SfCommand<CpqSettingsSetResult> {
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
Expand Down
11 changes: 5 additions & 6 deletions src/commands/texei/org/contractfieldhistory/fix.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,20 @@ export default class Fix extends SfCommand<OrgContractFieldHistoryResult> {
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();
Expand Down

0 comments on commit d6ee9ea

Please sign in to comment.