jquery - 如何使柏树操作可选?
问题描述
我正在进行柏树测试,我遇到了这个问题。有一种方法可以在我从按标题单击调用的确切区域中按标题单击。我想让它成为可选的,例如,如果有一个额外的弹出窗口包含一个我想通过函数传递的单词,我想执行它 - 否则,如果它不包含它 - 不要做任何事情。我通过这些值传递: .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");
}
});
}
解决方案
推荐阅读
- reactjs - 为什么我的 AsyncStorage.getItem().then 在 React Native 中未定义?
- c++ - 如何在 linux 中找到系统内存泄漏?
- php - docker 不使用 symfony 和 monolog 捕获 php-fpm 输出
- android - 我可以获取用户当前的铃声/振动设置吗
- javascript - “位置 0 处 JSON 中的意外令牌 a”的解决方案
- android - 如何从我的应用中禁用所有 android 应用的屏幕覆盖权限?
- java - textField.getText 方法在 javafx 中抛出空指针异常
- c# - 如何在 Microsoft Bot Builder 中保留默认消息计数器并更改 Bot 响应?
- powershell - Powershell - 从远程机器上运行 exe 的 Invoke-Command 捕获输出
- java - 我可以创建一个生成多个可执行 Jar 的 Eclipse 项目吗?