Control windows or file explorer to upload files in protractor

∥☆過路亽.° 提交于 2020-02-16 09:27:28

问题


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:

  1. Click on upload button
  2. File explorer opens.
  3. Enter the path
  4. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!