@sap_oss/wdio-qmate-service
Version:
[](https://api.reuse.software/info/github.com/SAP/wdio-qmate-service)[](http
185 lines • 7.88 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ElementModule = void 0;
const verboseLogger_1 = require("../../helper/verboseLogger");
const errorHandler_1 = __importDefault(require("../../helper/errorHandler"));
const elementResolving_1 = require("../../helper/elementResolving");
const constants_1 = require("../constants");
/**
* @class element
* @memberof mobile
*/
class ElementModule {
vlf = new verboseLogger_1.VerboseLoggerFactory("mobile", "element");
ErrorHandler = new errorHandler_1.default();
/**
* @function isVisible
* @memberof mobile.element
* @description Returns a boolean if the mobile element is visible to the user.
* @param {Element} element - The Mobile Ui element.
* @param {boolean} [strict=true] - If strict mode is enabled it will only return "true" if the element is visible on the mobile view and within the viewport.
* If "false", it will be sufficient if the element is visible on the view but not inside the current viewport.
* @returns {boolean} Returns true or false.
* @example
* await mobile.element.isVisible(elem);
*/
async isVisible(element, strict = true) {
const vl = this.vlf.initLog(this.isVisible);
try {
if (strict) {
return element.isDisplayedInViewport();
}
else {
return element.isDisplayed();
}
}
catch (error) {
return this.ErrorHandler.logException(error);
}
}
/**
* @function isPresent
* @memberof mobile.element
* @description Returns a boolean if the element is present at the DOM or not. It might be hidden.
* @param {Element} element - The element.
* @returns {boolean} Returns true or false.
* @example
* await mobile.element.isPresent(elem);
*/
async isPresent(element) {
const vl = this.vlf.initLog(this.isPresent);
return element.isExisting();
}
/**
* @function waitToBePresent
* @memberof mobile.element
* @description Waits until the element with the given selector is present.
* @param {Object} selector - The CSS selector describing the element.
* @param {number} [timeout = 30000] - The timeout to wait (ms).
* @returns {boolean} Returns true or false.
* @example
* await mobile.element.waitToBePresent(".input01");
* await mobile.element.waitToBePresent("#button12");
* await mobile.element.waitToBePresent("p:first-child");
*/
async waitToBePresent(selector, timeout = parseFloat(process.env.QMATE_CUSTOM_TIMEOUT) || constants_1.GLOBAL_DEFAULT_WAIT_TIMEOUT) {
const vl = this.vlf.initLog(this.waitToBePresent);
try {
vl.log(`wdio.waitForExist invocation for selector ${selector}`);
await $(selector).waitForExist({
timeout: timeout,
interval: constants_1.GLOBAL_DEFAULT_WAIT_INTERVAL,
timeoutMsg: `Timeout '${+timeout / 1000}s' by waiting for element is present.`
});
return true;
}
catch (error) {
this.ErrorHandler.logException(error);
return false;
}
}
/**
* @function waitToBeVisible
* @memberof mobile.element
* @description Waits until the element with the given selector is visible.
* @param {Object} selector - The CSS selector describing the element.
* @param {number} [timeout=30000] - The timeout to wait (ms).
* @returns {boolean} Returns true or false.
* @example
* await mobile.element.waitToBeVisible(".input01");
* await mobile.element.waitToBeVisible("#button12");
* await mobile.element.waitToBeVisible("p:first-child");
*/
async waitToBeVisible(selector, timeout = parseFloat(process.env.QMATE_CUSTOM_TIMEOUT) || constants_1.GLOBAL_DEFAULT_WAIT_TIMEOUT) {
const vl = this.vlf.initLog(this.waitToBeVisible);
try {
vl.log(`wdio.waitForDisplayed invocation for selector ${selector}`);
await $(selector).waitForDisplayed({
timeout: timeout,
interval: constants_1.GLOBAL_DEFAULT_WAIT_INTERVAL,
timeoutMsg: `Timeout '${+timeout / 1000}s' by waiting for element is displayed.`
});
return true;
}
catch (error) {
this.ErrorHandler.logException(error);
return false;
}
}
/**
* @function waitToBeClickable
* @memberof mobile.element
* @description Waits until the element with the given selector is clickable.
* @param {Object} selector - The CSS selector describing the element.
* @param {number} [timeout=30000] - The timeout to wait (ms).
* @returns {boolean} Returns true or false.
* @example
* await mobile.element.waitToBeClickable(".input01");
* await mobile.element.waitToBeClickable("#button12");
* await mobile.element.waitToBeClickable("p:first-child");
*/
async waitToBeClickable(selector, timeout = parseFloat(process.env.QMATE_CUSTOM_TIMEOUT) || constants_1.GLOBAL_DEFAULT_WAIT_TIMEOUT) {
const vl = this.vlf.initLog(this.waitToBeClickable);
try {
vl.log(`wdio.waitForClickable invocation for selector ${selector}`);
await $(selector).waitForClickable({
timeout: timeout,
interval: constants_1.GLOBAL_DEFAULT_WAIT_INTERVAL,
timeoutMsg: `Timeout '${+timeout / 1000}s' by waiting for element is clickable.`
});
return true;
}
catch (error) {
this.ErrorHandler.logException(error);
return false;
}
}
/**
* @function isSelected
* @memberof mobile.element
* @description Returns a boolean if the element (e.g. checkbox) is selected.
* @param {Element | string} elementOrSelector - The element.
* @returns {boolean} Returns true or false.
* @example
* const isSelected = await mobile.element.isSelected(elem);
*/
async isSelected(elementOrSelector) {
const vl = this.vlf.initLog(this.isSelected);
const element = await (0, elementResolving_1.resolveMobileSelectorOrElement)(elementOrSelector);
return await element.isSelected();
}
/**
* @function waitToBeEnabled
* @memberof mobile.element
* @description Waits until the element with the given selector is present.
* @param {Object} selector - The CSS selector describing the element.
* @param {number} [timeout=30000] - The timeout to wait (ms).
* @returns {boolean} Returns true or false.
* @example
* await mobile.element.waitToBeEnabled(".input01");
* await mobile.element.waitToBeEnabled("#button12");
* await mobile.element.waitToBeEnabled("p:first-child");
*/
async waitToBeEnabled(selector, timeout = parseFloat(process.env.QMATE_CUSTOM_TIMEOUT) || constants_1.GLOBAL_DEFAULT_WAIT_TIMEOUT) {
const vl = this.vlf.initLog(this.waitToBeEnabled);
try {
vl.log(`wdio.waitTotoBeEnabled invocation for selector ${selector}`);
await $(selector).toBeEnabled({
timeout: timeout,
interval: constants_1.GLOBAL_DEFAULT_WAIT_INTERVAL,
timeoutMsg: `Timeout '${+timeout / 1000}s' by waiting for element is enabled.`
});
return true;
}
catch (error) {
this.ErrorHandler.logException(error);
return false;
}
}
}
exports.ElementModule = ElementModule;
exports.default = new ElementModule();
//# sourceMappingURL=element.js.map