browser-actions
Version:
Implementing Re-Usable Browser Actions For Cypress
29 lines (27 loc) • 1.04 kB
JavaScript
class ReturnLocator {
/**
* @param elementObj is location obeject
* @example new ReadLocator().returnElement(pageLocatorsObj.locatorObj)
*/
returnElement(elementObj, timeout) {
let element;
if (Object.keys(elementObj)[0] === "cypath") {
return cy.get(`${Object.values(elementObj)[0]}`, { timeout });
} else if (Object.keys(elementObj)[0] === "xpath") {
element = cy.xpath(`${Object.values(elementObj)[0]}`, { timeout });
} else if (Object.keys(elementObj)[0] === "id") {
return cy.get(`#${Object.values(elementObj)[0]}`, { timeout });
} else if (Object.keys(elementObj)[0] === "class") {
return cy.get(`.${Object.values(elementObj)[0]}`, { timeout });
} else if (Object.keys(elementObj)[0] === "attributeValue") {
return cy.get(
`[${Object.keys(elementObj.attributeValue)[0]}=${
Object.values(elementObj.attributeValue)[0]
}]`,
{ timeout }
);
}
return element;
}
}
module.exports = ReturnLocator;