在赛普拉斯,select('option-text')
命令仅在完全匹配时才有效。如何告诉它选择包含文本的选项?
到目前为止,我还没有在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>;
}
}