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

add 'selectBoxByKey()' to support finding items in selectBox by Key #258

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from 2 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
69 changes: 36 additions & 33 deletions src/reuse/modules/ui5/userInteraction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ export class UserInteraction {
});
} catch (error) {
// @ts-ignore
this.ErrorHandler.logException(error);
this.ErrorHandler.logException(error);
}
}

Expand Down Expand Up @@ -269,14 +269,7 @@ export class UserInteraction {
* @param {Number} [interval=5000] - The delay between the retries (ms). Can be set in config for all functions under params.stepRetriesIntervals.
* @example await ui5.userInteraction.fillAndRetry(selector, "My Value");
*/
async fillAndRetry(
selector: any,
value: string | number,
index = 0,
timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000,
retries = 3,
interval = 5000
) {
async fillAndRetry(selector: any, value: string | number, index = 0, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000, retries = 3, interval = 5000) {
const vl = this.vlf.initLog(this.fillAndRetry);
await util.function.retry(this.fill, [selector, value, index, timeout], retries, interval, this);
}
Expand Down Expand Up @@ -347,15 +340,7 @@ export class UserInteraction {
* @param {Boolean} [verify=true] - Specifies if the filled value should be verified.
* @example await ui5.userInteraction.clearAndFillAndRetry(selector, "My Value");
*/
async clearAndFillAndRetry(
selector: any,
value: string,
index = 0,
timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000,
retries = 3,
interval = 5000,
verify = true
) {
async clearAndFillAndRetry(selector: any, value: string, index = 0, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000, retries = 3, interval = 5000, verify = true) {
const vl = this.vlf.initLog(this.clearAndFillAndRetry);
await util.function.retry(
async (selector: any, value: string, index: number, timeout: number) => {
Expand Down Expand Up @@ -425,14 +410,7 @@ export class UserInteraction {
* @param {Number} [interval=5000] - The delay between the retries (ms). Can be set in config for all functions under params.stepRetriesIntervals.
* @example await ui5.userInteraction.clearAndFillSmartFieldInputAndRetry(selector, "My Value");
*/
async clearAndFillSmartFieldInputAndRetry(
selector: any,
value: string,
index = 0,
timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000,
retries = 3,
interval = 5000
) {
async clearAndFillSmartFieldInputAndRetry(selector: any, value: string, index = 0, timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000, retries = 3, interval = 5000) {
const vl = this.vlf.initLog(this.clearAndFillSmartFieldInputAndRetry);
await util.function.retry(this.clearAndFillSmartFieldInput, [selector, value, index, timeout], retries, interval, this);
}
Expand Down Expand Up @@ -468,6 +446,36 @@ export class UserInteraction {
}
}

/**
* @function selectBoxByKey
* @memberOf ui5.userInteraction
* @description Selects the passed value of the Select box.
* Please note that the function will only work for the default select Box.
* In special cases, please use the clickSelectArrow function.
* @param {Object} selector - The selector describing the element.
* @param {String} keyValue - The value to select.
* @param {Number} [index=0] - The index of the selector (in case there are more than one elements visible at the same time).
* @example await ui5.userInteraction.selectBox(selector, "DE");
*/
async selectBoxByKey(selector: any, keyValue: string, index = 0) {
const vl = this.vlf.initLog(this.selectBoxByKey);
await this.clickSelectArrow(selector, index);
if (keyValue !== undefined && keyValue !== null) {
const itemSelector = {
elementProperties: {
mProperties: {
key: keyValue
},
ancestorProperties: selector.elementProperties
}
};
await this.scrollToElement(itemSelector);
await this.click(itemSelector);
} else {
this.ErrorHandler.logException(new Error("Please provide a value as second argument."));
}
}

/**
* @function selectComboBox
* @memberOf ui5.userInteraction
Expand Down Expand Up @@ -624,7 +632,7 @@ export class UserInteraction {
try {
elem = await ui5.element.getDisplayed(selector, index, timeout);
} catch (error) {
return this.ErrorHandler.logException(new Error(),`No element found for selector ${selector}`);
return this.ErrorHandler.logException(new Error(), `No element found for selector ${selector}`);
}
await elem.moveTo();
}
Expand Down Expand Up @@ -653,12 +661,7 @@ export class UserInteraction {
* };
* await nonUi5.userInteraction.scrollToElement(selector, 0, alignment);
*/
async scrollToElement(
selector: any,
index = 0,
alignment: AlignmentOptions | AlignmentValues = "center",
timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000
) {
async scrollToElement(selector: any, index = 0, alignment: AlignmentOptions | AlignmentValues = "center", timeout = process.env.QMATE_CUSTOM_TIMEOUT || 30000) {
const vl = this.vlf.initLog(this.scrollToElement);
let options = {};
const elem = await ui5.element.getDisplayed(selector, index, timeout);
Expand Down
Loading