控制窗口或文件资源管理器在量角器中上传文件 [英] Control windows or file explorer to upload files in protractor

查看:18
本文介绍了控制窗口或文件资源管理器在量角器中上传文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在量角器 E2E 测试中上传文件.谷歌搜索了一下,我最终使用了robotJS.不幸的是,robotJS 的安装失败了.有没有其他方法可以让我的文件上传.

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.

步骤:

  1. 点击上传按钮
  2. 文件浏览器打开.
  3. 输入路径
  4. 点击上传.

我尝试使用 FileDetector,下面是代码:

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 ?

推荐答案

如果您的文件夹 e2e 有 2 个文件夹:包含您的测试的文件夹 tests 和包含 testFile 的文件夹图像,试试这个:

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);

这篇关于控制窗口或文件资源管理器在量角器中上传文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆