Skip to content

Commit

Permalink
Merge pull request #166 from w-andre/master
Browse files Browse the repository at this point in the history
[Set CPQ Settings] Wait for asynchronously loaded select options to be available
  • Loading branch information
FabienTaillon authored Jun 12, 2024
2 parents 5c94656 + 821bed1 commit de8c4eb
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/commands/texei/cpqsettings/set.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,14 @@ export default class Set extends SfCommand<CpqSettingsSetResult> {
this.spinner.stop('Text Value already ok');
}
} else if (targetType === 'select') {
await targetInput.waitForSelector(`xpath///option[text()='${cpqSettings[tabKey][key]}']`);
const selectedOptionValue = await (await targetInput?.getProperty('value'))?.jsonValue();
// wait until option value is loaded and get select input for further processing
await page.waitForXPath(`${xpath}//option[text()='${cpqSettings[tabKey][key]}']`);
const targetSelectInputs = await page.$x(xpath);
const targetSelectInput = targetSelectInputs[0] as ElementHandle<Element>;

const selectedOptionElement = await targetInput.$(`option[value='${selectedOptionValue}']`);
const selectedOptionValue = await (await targetSelectInput?.getProperty('value'))?.jsonValue();

const selectedOptionElement = await targetSelectInput.$(`option[value='${selectedOptionValue}']`);
currentValue = (await (await selectedOptionElement?.getProperty('text'))?.jsonValue()) as string;

if (currentValue !== cpqSettings[tabKey][key]) {
Expand All @@ -168,10 +172,10 @@ export default class Set extends SfCommand<CpqSettingsSetResult> {
);

const optionElement = (
await targetInput.$$(`xpath///option[text()='${cpqSettings[tabKey][key]}']`)
await targetSelectInput.$$(`xpath///option[text()='${cpqSettings[tabKey][key]}']`)
)[0] as ElementHandle<HTMLOptionElement>;
const optionValue = await (await optionElement.getProperty('value')).jsonValue();
await targetInput.select(optionValue);
await targetSelectInput.select(optionValue);

this.spinner.stop(`Picklist Value updated from ${currentValue} to ${cpqSettings[tabKey][key]}`);
} else {
Expand Down

0 comments on commit de8c4eb

Please sign in to comment.