i am working on a cypress project and I am trying to create a custom command which resolves promise and returns text on the passed locator.
export default class QuickRegisterPage {
emailAddressText() {
return cy.get('#emailAddress');
}
public createNewUser() {
cy.getQuickRegisterUrl().then(url => {
cy.visit(url);
text = cy.getText(this.emailAddressText());
cy.log(text);
});
}
Cypress.Commands.add(
'getText',
(element: Cypress.Chainable<JQuery<HTMLElement>>) => {
element.scrollIntoView();
element.then(ele => {
const text = ele.text();
return text;
});
}
);
declare namespace Cypress {
interface Chainable<Subject = any> {
getText(element: Cypress.Chainable<JQuery<HTMLElement>>): string;
}
}
when I am calling cy.getText()
nothing is happening it's just sitting there and not returning the text.
can someone help me to resolve this.