赛普拉斯如何选择包含文本的选项

问题描述 投票:0回答:1

在赛普拉斯,select('option-text')命令仅在完全匹配时才有效。如何告诉它选择包含文本的选项?

cypress
1个回答
0
投票

到目前为止,我还没有在api中找到类似的东西,也没有在github问题中找到类似的东西。

所以我在我的项目中添加了一个custom command

// cypress/support/commands.ts
Cypress.Commands.add('selectContaining', {prevSubject: 'element'}, (subject, text, options) => {
  return cy.wrap(subject).contains('option', text, options).then(
    option => cy.get('select#report-selection').select(option.text().trim())
  );
});
// cypress/support/commands_type.ts
declare namespace Cypress {
  interface Chainable<Subject = any> {
    requestApi(method: HttpMethod, url: string, body?: RequestBody): Chainable<Cypress.Response>;
    selectContaining(text: string | string[], options?: Partial<SelectOptions>): Chainable<Subject>;
  }
}
© www.soinside.com 2019 - 2024. All rights reserved.