首页 > 解决方案 > 如何使柏树操作可选?

问题描述

我正在进行柏树测试,我遇到了这个问题。有一种方法可以在我从按标题单击调用的确切区域中按标题单击。我想让它成为可选的,例如,如果有一个额外的弹出窗口包含一个我想通过函数传递的单词,我想执行它 - 否则,如果它不包含它 - 不要做任何事情。我通过这些值传递: .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");
            }
        });
}

标签: jquerytestingjquery-uicypressui-testing

解决方案


推荐阅读