我正在从 Protractor 转换为 Cypress,我遇到了一个案例,我可以cy.get(...).select()
选择适当的选项,但验证失败了。 >
它的 'have.text'
值(在视觉上改变之后)最终成为所有选项的长字符串。
这些是我的页面对象函数:
getOwnerField() {
return cy.get('select[name="owner"]')
}
setOwnerField(val: string) {
return this.getOwnerField().select(val).should('have.text', val)
}
Angular8 生成的 HTML 是:
<select _ngcontent-epq-c4="" class="select form-control ng-valid ng-dirty ng-touched" formcontrolname="owner_id" name="owner" ng-reflect-klass="select form-control" ng-reflect-ng-class="[object Object]" ng-reflect-name="owner_id">
<option _ngcontent-epq-c4="" value="" ng-reflect-value="">---------</option>
<!--bindings={
"ng-reflect-ng-for-of": "[object Object],[object Object"
}-->
<option _ngcontent-epq-c4="" value="1" ng-reflect-value="1">e2e</option>
<option _ngcontent-epq-c4="" value="2" ng-reflect-value="2">e2e_team_member00</option>
<option _ngcontent-epq-c4="" value="3" ng-reflect-value="3">e2e_team_member01</option>
<option _ngcontent-epq-c4="" value="4" ng-reflect-value="4">e2e_team_member02</option>
<option _ngcontent-epq-c4="" value="5" ng-reflect-value="5">e2e_team_member03</option>
<option _ngcontent-epq-c4="" value="6" ng-reflect-value="6">other00</option>
<option _ngcontent-epq-c4="" value="7" ng-reflect-value="7">other01</option>
<option _ngcontent-epq-c4="" value="8" ng-reflect-value="8">other02</option>
<option _ngcontent-epq-c4="" value="9" ng-reflect-value="9">other03</option>
</select>
在选择的同时观看 chrome 调试器时,我没有看到 HTML 有任何变化。
如何验证所选选项?
答案 0 :(得分:0)
您必须find()
选择的选项:
setOwnerField(val: string) {
this.getOwnerField().select(val).find('option:selected').should('have.text', val)
}