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

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

问题描述

所以,我已经打了一下碰钉子的。我试图自动化测试情况下,我需要多个文件传递给输入节点,我无法弄清楚如何做到这一点。我可以使用机械化或的Watir,但发现,似乎在自动化相对大的话题很少的信息。在下面的代码片段,我用的Watir使用Ruby。我遇到的主要问题是,它似乎在选中多个文件,输入节点不再可见。输入节点不接受多个文件,并通过在单一路径中导致上传成功,像这样。

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

我认为传递多个文件将作为传递由某种分隔符分隔的多个路径字符串一样简单。我不是web开发特别精明不过了,我奋力抓住其中,我甚至应该开始。当我尝试在多个文件通过像这样:

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提供了上传使用\\ n多个文件作为分隔符一种解决方法,有没有类似的解决方法Firefox的?

Do you think this is even possible using Watir? I know that Chrome has a workaround for uploading multiple files using \n 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\npath/to/second/file.json\n...etc
file_field.send_keys paths

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

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