使用 Watir 将多个文件传递到输入节点(使用 Ruby) [英] Passing multiple files to input node with Watir (using Ruby)

查看:30
本文介绍了使用 Watir 将多个文件传递到输入节点(使用 Ruby)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我遇到了一些障碍.我正在尝试自动化一个测试用例,我需要将多个文件传递给一个输入节点,但我不知道该怎么做.我可以使用 Mechanize 或 Watir,但在自动化方面似乎相对重要的主题上几乎没有找到相关信息.在下面的片段中,我将 Watir 与 Ruby 结合使用.The main issue I'm having is that it seems when multiple files are selected, the input node is no longer visible.输入节点确实接受多个文件,并且传入单个路径确实会导致成功上传,就像这样.

So I have hit a bit of a snag. I am trying to automate a test case where I need to pass multiple files to an input node and I cannot figure out how to do so. I can use either Mechanize or Watir, but have found very little information on a topic that seems relatively major in automation. In the snippets below, I'm using Watir with Ruby. The main issue I'm having is that it seems when multiple files are selected, the input node is no longer visible. The input node does accept multiple files, and passing in a single path does result in a successful upload, like so.

path1 = "/path/to/file.json"
file_field.set path1

我认为传入多个文件就像传入一个字符串一样简单,多个路径由某种分隔符分隔.然而,我对网络开发并不是特别精通,并且正在努力掌握我应该从哪里开始.当我尝试像这样传入多个文件时:

I would think that passing in multiple files would be as simple as passing in a string with multiple paths separated by some sort of delimiter. I'm not particularly savvy with web dev however, and am struggling to grasp where I should even start. When I attempt to pass in multiple files like so:

multiple_paths = ("/path/to/file1.json"; "/path/to/file2.json")
file_field.set multiple_paths

它上传第二个文件而不是第一个(让我觉得它可能是按顺序上传它们,而第二个是覆盖).

it gives uploads the second file but not the first (making me think maybe it's uploading them in sequence, and the second is overwriting).

您认为使用 Watir 甚至可以做到吗?我知道 Chrome 有一种使用 作为分隔符上传多个文件的解决方法,Firefox 是否有类似的解决方法?

Do you think this is even possible using Watir? I know that Chrome has a workaround for uploading multiple files using as the delimiter, is there a similar workaround for Firefox?

推荐答案

目前似乎没有适用于 Firefox 的解决方法.如果有人知道,请发布答案,因为我在任何地方都找不到解决方案.我想我会在这里发布 Chrome 的解决方案,因为这方面的资源很少.

Currently there doesn't seem to be a workaround for Firefox. If anybody knows of one, please post the answer as I couldn't find a solution anywhere. I figured I'd post the solution for Chrome here because resources are scarce on this.

如果您需要测试多个文件上传,请让该特定实例加载 Chrome 驱动程序:

If you need to test for multiple file uploads, have that particular instance load the Chrome driver with:

@browser = Watir::Browser.new :chrome, :prefs => profile

然后你会想要传递一个看起来像这样的字符串:

Then you're going to want to pass it a string that looks something like this:

paths = "path/to/first/file.json
path/to/second/file.json
...etc
file_field.send_keys paths

这篇关于使用 Watir 将多个文件传递到输入节点(使用 Ruby)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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