I am working on cypress tests and I came to this problem. There's a method who clicks by title in exact area which I call from Click by title. I want to make it optional for example if there's an additional pop up window containing a word I pass through function I would like to perform it - otherwise, if it doesn't contain it - don't do anything. I pass trough these values: .ClickByTitle("Emergency Access", undefined, true);
/**
* Finds clickable element (button) by provided title and clicks it.
* @param {string} title clickable element title
* @param {string} [sectionTitle] section title
* @example Extensions.Interactor.ClickByTitle("Save");
*/
public ClickByTitle(title: string, sectionTitle?: string, operationIsOptional = false): void {
this.ClickByTitleInExactArea(this.elementSearch.TryGetSection(sectionTitle), title, operationIsOptional);
}
/**
* Finds clickable element (button) in provided exact area by provided title and clicks it.
* @param {Cypress.Chainable<JQuery<HTMLHtmlElement>>} area
* @param {string} title
*/
public ClickByTitleInExactArea(area: Cypress.Chainable<JQuery<HTMLHtmlElement>>, title: string, operationIsOptional = false): void {
area
.find("a")
.contains(new RegExp(`^${title}$`, "g"))
.first().then($clickableElement => {
const isButton = $clickableElement.hasClass(this.buttonClass);
const buttonId = $clickableElement.attr("id");
cy.wrap($clickableElement).click();
if (isButton) {
cy.get(`#${buttonId}.${this.buttonLoadingClass}`, { timeout: GlobalDefaults.TimeOut }).should("not.be.visible");
cy.get(`#${buttonId}`, { timeout: GlobalDefaults.TimeOut }).should("not.be.disabled");
cy.get(`#${buttonId}_Cloned.${this.buttonLoadingClass}`, { timeout: GlobalDefaults.TimeOut }).should("not.be.visible");
}
});
}
Aucun commentaire:
Enregistrer un commentaire