【发布时间】:2019-01-04 21:29:48
【问题描述】:
我在 Angular 应用程序中测试 Cypress 中的文件上传方案时遇到问题。 这些是步骤:
用户选择一个文件,点击“选择”并弹出一个表单并打开模式。
用户填写表格并点击确定。
文件被上传,表单值被发送到服务器。
赛普拉斯不支持文件选择器。但是我需要测试用户在选择文件时所做的其他步骤。如果在应用程序中此功能由文件输入更改事件触发,我如何在赛普拉斯中触发打开弹出窗口的功能?也许可以在测试中触发该功能(类似于单元测试,即 component.setSelectedFiles() )并完全绕过文件选择器?
App.component.html
<label class="btn" (click)="$event.stopPropagation()">
Upload
<input type="file" multiple (change)="setSelectedFiles($event.target.files)">
</label>
App.component.ts
setSelectedFiles(fileArray) { // This function is triggered when user selects a file
this.files = fileArray
this.showModal = true // this step opens a modal pop up.
}
【问题讨论】: