I am facing an issue in Angular where in for the purpose of automation testing , I want to bypass a 'file open dialog' box and give the ability of typing in the file path to testers. Now the issue I know how to upload a file using an input type="file" behavior but then how do i achieve the same when input type="text" and i type in the file path and the file itself is captured from my local drive ?
<div class="col-8">
<mat-form-field style="width:100%; max-width:50%;">
<input matInput type="text" id="file" formControlName="file" [placeholder]="l('ImportFile')" (keydown.enter)="onFileSelected($event)" required>
</mat-form-field>
<input class="file-input" type="file" #fileBrowser (change)="onFileChange($event)" />
<button type="button" #browseButton class="btn btn-primary ml-3" id="browseButton" (click)="fileBrowser.click()">{{l("Browse")}}</button>
</div>
The file should be captured if i type in the file path and i have an event keydown.enter binded for the user. How should I approach for the solution?
public onFileSelected(event){
this.fileToImport = event.target.value;
this.theForm.controls.file.markAsTouched();
this.theForm.controls.file.setValue(event.target.value);
}
target.value is giving me the file path but not the file itself.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…