'How can I upload file to the field in cypress? But field's type is text

I used different ways. But can not handle.

cy.get('#form-group-936cd4f5-19ab-4f3c-bfd9-563bf46212b3 > .fal')
        .click()    
        .attachFile('files/sample.pdf', {force: true})

cy.get('#form-group-936cd4f5-19ab-4f3c-bfd9-563bf46212b3 > .form-control)   
        .attachFile('files/sample.pdf', {force: true})

cy.get('#form-group-936cd4f5-19ab-4f3c-bfd9-563bf46212b3 > .fal')
        .attachFile('files/sample.pdf', {subjectType: 'drag-n-drop'})

HTML

<div _ngcontent-ete-c120="" class="form-group upload-doc ng-star-inserted" id="form-group-936cd4f5-19ab-4f3c-bfd9-563bf46212b3">                         <label _ngcontent-ete-c120="" class="ng-star-inserted">Please provide bank account statement</label><!---->                         <input _ngcontent-ete-c120="" type="text" readonly="" class="form-control ng-untouched ng-pristine ng-valid"><i _ngcontent-ete-c120="" class="fal fa-upload"></i>                         <!---->                          <!---->                       </div> – 

Hidden file upload input

<input _ngcontent-juf-c120="" type="file" ng2fileselect="" class="uploader" accept="application/pdf,application/acrobat,application/nappdf,application/x-pdf,image/pdf,image/jpeg,image/pjpeg,image/png">

enter image description here



Solution 1:[1]

cypress-file-upload only checks type="file" for subjectType: 'drag-n-drop' option, the default subjectType: 'input' does not check.

Cannot tell it your test are any good, there not enough info given (except the 3rd will not work).

Pause and inspect the DOM after #1 & #2, to see if there's a valid attachment DTO.

But attaching the file is only part of the story, you will need to find out what event is used and .trigger() it.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Fody