Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drop down #501

Merged
merged 8 commits into from
Dec 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 27 additions & 5 deletions backend/features/step_definitions/stepdefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -462,15 +462,37 @@ When('I select {string} from the selection {string}', async function clickRadioB
});

// Select an Option from a dropdown-menu
When('I select the option {string} from the drop-down-menue {string}', async (value, dropd) => {
let world;
When('I select the option {string} from the drop-down-menue {string}', async function (value, dropd) {
const world = this;
const identifiers = [`//*[@*='${dropd}']/option[text()='${value}']`, `//label[contains(text(),'${dropd}')]/following::button[text()='${value}']`,
`//label[contains(text(),'${dropd}')]/following::span[text()='${value}']`, `//*[contains(text(),'${dropd}')]/following::*[contains(text(),'${value}']`, `${dropd}`];
const promises = [];
for (const idString of identifiers) promises.push(driver.wait(until.elementLocated(By.xpath(idString)), searchTimeout, `Timed out after ${searchTimeout} ms`, 100));
`//label[contains(text(),'${dropd}')]/following::span[text()='${value}']`, `//*[contains(text(),'${dropd}')]/following::*[contains(text(),'${value}']`, `//*[@role='listbox']//*[self::li[@role='option' and text()='${value}'] or parent::li[@role='option' and text()='${value}']]`,
`${dropd}//option[contains(text(),'${value}') or contains(@id, '${value}') or contains(@*,'${value}')]`];
const promises = identifiers.map((idString) =>
driver.wait(
until.elementLocated(By.xpath(idString)),
searchTimeout,
`Timed out after ${searchTimeout} ms`,
100
)
);

await Promise.any(promises)
.then((elem) => elem.click())
.catch(async (e) => {
const ariaProm = [driver.findElement(By.xpath(`//*[contains(text(),"${dropd}") or contains(@id, "${dropd}") or contains(@*, "${dropd}")]`)), driver.findElement(By.xpath(`${dropd}`))];
const dropdownElement = await Promise.any(ariaProm);
await dropdownElement.click();

const ariaOptProm = [driver.findElement(By.xpath(`(//*[contains(text(),'${value}') or contains(@id, '${value}') or contains(@*, '${value}')]/option) | (//*[@role='listbox']//*[ancestor::*[@role='option']//*[contains(text(),'${value}')]])
`)), driver.findElement(By.xpath(`${value}`))];
const dropdownOption = await Promise.any(ariaOptProm).catch((e) => { throw e; });

// Wait for the dropdown options to be visible
await driver.wait(until.elementIsVisible(dropdownOption)).catch((e) => { throw e; });

// Select the option from the dropdown
await dropdownOption.click();
})
.catch(async (e) => {
await driver.takeScreenshot().then(async (buffer) => {
world.attach(buffer, 'image/png');
Expand Down
Loading