@sap_oss/wdio-qmate-service
Version:
[](https://api.reuse.software/info/github.com/SAP/wdio-qmate-service)[](http
76 lines • 3.78 kB
JavaScript
;
//"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.ElementHighlight = void 0;
const verboseLogger_1 = require("./verboseLogger");
/**
* @class ElementHighlight
* @memberof helper
*/
class ElementHighlight {
vlf = new verboseLogger_1.VerboseLoggerFactory("util", "elementHighlight");
/**
* @function getElementHighlightData
* @memberof helper
* @description - It is used to get the element highlight data based on the action method matched
* @returns - Promise object
* @param {string} actionName - action name is required
* @example await elementHighlight.getElementHighlightData("click");
*/
async getElementHighlightData(actionName) {
const vl = this.vlf.initLog(this.getElementHighlightData);
let elementHighlightDefaultConfig = {
enable: false,
duration: 1000,
color: "red"
};
if (browser.config.params) {
let elementHighlightConfig = browser.config.params.highlightElements;
if (elementHighlightConfig && elementHighlightConfig.enable) {
let actions = elementHighlightConfig.actions;
if (!actions)
throw new Error("Please specify the actions key in element highlight config object");
if (Array.isArray(actions)) {
for (let action of actions) {
if (!(typeof action == "string" && typeof actionName == "string"))
throw new Error(`Please provide the method name '${action}/${actionName}' in string format`);
if (action.toLowerCase().trim().includes(actionName.trim()) || action.includes("*")) {
elementHighlightConfig = this._getElementHighlightColorAndDuration(elementHighlightConfig, elementHighlightDefaultConfig);
return this._getElementHighlightConfig(true, elementHighlightConfig.color, elementHighlightConfig.duration);
}
}
}
else if (typeof actions === "string" && typeof actionName === "string") {
if (actions.toLowerCase().trim().includes(actionName.trim()) || actions.includes("*")) {
elementHighlightConfig = this._getElementHighlightColorAndDuration(elementHighlightConfig, elementHighlightDefaultConfig);
return this._getElementHighlightConfig(true, elementHighlightConfig.color, elementHighlightConfig.duration);
}
}
else {
throw new Error(`Please provide the method name '${actions}/${actionName}' in string format`);
}
}
}
return elementHighlightDefaultConfig;
}
// =================================== HELPER ===================================
_getElementHighlightConfig(enabled, colorName, timeout) {
return {
enable: enabled,
color: colorName,
duration: timeout
};
}
_getElementHighlightColorAndDuration(elementHighlightConfig, elementHighlightDefaultConfig) {
elementHighlightConfig.color = elementHighlightConfig.hasOwnProperty("color")
? elementHighlightConfig.color
: elementHighlightDefaultConfig.color;
elementHighlightConfig.duration = elementHighlightConfig.hasOwnProperty("duration")
? elementHighlightConfig.duration
: elementHighlightDefaultConfig.duration;
return elementHighlightConfig;
}
}
exports.ElementHighlight = ElementHighlight;
exports.default = new ElementHighlight();
//# sourceMappingURL=elementHighlight.js.map