Angular 从Mat中选择选项使用cypress选择

Angular 从Mat中选择选项使用cypress选择,angular,angular-material,angular7,cypress,Angular,Angular Material,Angular7,Cypress,我有Mat select下拉列表,如下所示 <mat-form-field> <mat-label>Gender</mat-label> <mat-select id="gender" required formControlName="gender"> <mat-option id="Male" value="male"> Male </mat-option> <

我有Mat select下拉列表,如下所示

<mat-form-field>
   <mat-label>Gender</mat-label>
      <mat-select id="gender" required formControlName="gender">
         <mat-option id="Male" value="male"> Male </mat-option>
         <mat-option value="female"> Female </mat-option>
      </mat-select>
 </mat-form-field>
使用上述代码,我得到以下错误:

CypressError: cy.select() can only be called on a <select>. Your subject is a: <mat-select>

基本上,我所做的是模拟下拉菜单打开,然后再次单击以选择项目:

//在下拉列表中模拟单击事件
cy.get('mat-select').first()
。单击();//打开下拉列表
//在下拉项(mat选项)上模拟单击事件
cy.get(“.mat选项文本span”)
.contains('您的MatItem文本')
。然后(选项=>{
选项[0]。单击();//这是jquery单击()而不是cypress单击()

});打开mat选择的mat选项对话框并选择包含“Apple Inc.”的字段


首先,单击“选择”打开覆盖,然后根据选项文本内容单击选项:

cy.get('mat-select[formcontrolname=“department”]”)。单击();
cy.get('mat-option')。包含('Lima')。单击();
我的选项文本是利马(+001)。当我查询
.contains('Lima')
时,我得到了“AssertionError”。但当我查询
.contains('Lima')
.contains('001')
元素时,就会找到它。在我看来,它只支持字母数字(我没有深入研究)


首先,选择打开覆盖,然后根据选项文本内容选择选项,并使用
should()
验证是否选择了正确的选项:


cy.get('mat-select').select('Male')。应该('have.value','Male')您检查过这个吗?为什么使用jQuery单击而不是Cypress?
CypressError: cy.select() can only be called on a <select>. Your subject is a: <mat-select>
cy.get('#gender').click().then(() => {
            cy.get('#male').click()
        })
cy.get('mat-select[formControlName=companyName]').click().get('mat-option').contains('Apple Inc.').click();