问题
I am trying to upload files in my protractor E2E test. Googling a bit I ended up using robotJS.
Unfortunately , the installation of robotJS
is failing.
Is there any other way to get my files uploaded.
Steps:
- Click on upload button
- File explorer opens.
- Enter the path
- click on upload.
I tried using FileDetector and below is the code:
let fileToUpload = 'testfolder';
let absolutePath = path.resolve(__dirname, fileToUpload);
await browser.setFileDetector(new remote.FileDetector());
$('input[type="file"]').sendKeys(absolutePath);
This doesn't really pass or search for the absolute path. What is missing here ?
回答1:
If you have folder e2e with 2 folders: folder tests containing your test and folder images containing testFile, try this:
const filePath = '../images/testFile';
const absolutePath = require('path').resolve(__dirname, filePath);
$('input[type="file"]').sendKeys(absolutePath);
来源:https://stackoverflow.com/questions/56151063/control-windows-or-file-explorer-to-upload-files-in-protractor