使用 selenium-client gem 上传文件
我正在使用 selenium-client gem 与 Webrat 和 Cucumber 来测试 Rails 项目。 我已经按照此处所述设置了 Cucumber: https://github.com /cucumber/cucumber/wiki/Setting-up-Selenium
我的问题是 Selenium 无法执行文件上传。 理想情况下,我希望能够复制 webrat 的“attach_file”方法。 我尝试通过使用 selenium-client 的“type”方法来输入所需文件的路径来避免这个问题,但这似乎失败了。
有人对使用 selenium-client (即不是常规的 Selenium gem)的解决方法有建议吗?
I am using the selenium-client gem with Webrat and Cucumber to test a rails project. I have Cucumber set up pretty much as described here: https://github.com/cucumber/cucumber/wiki/Setting-up-Selenium
My problem is that Selenium is prevented from performing file uploads. Ideally I'd like to be able to replicate webrat's 'attach_file' method. I tried dodging the issue by using selenium-client's 'type' method to type the path to the required file, but this seems to fail.
Does anyone have a sugestion for a workaround using selenium-client (i.e. not the regular Selenium gem)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我终于明白了这一点。
您需要将 Firefox 与 chrome 后端一起使用,并且需要指定绝对文件路径。
我最终创建了一个帮助程序模块来指定文件路径,以及一个包含测试内容的“fixtures”文件夹。 这是我提出的解决方案的要点: http://gist.github.com/214185
因此完全可以复制Webrat的attach_file方法!
I finally figured this out.
You need to be using firefox with the chrome backend, and you need to specifiy an absolute filepath.
I ended up creating a helper module to specify the filepath, and a "fixtures" folder containing test content. Here is a gist of the solution I came up with: http://gist.github.com/214185
Therefore it is totally possible to replicate Webrat's attach_file method!
普通的 selenium 无法做到这一点,因为浏览器安全性会阻止 javascript 写入 input=file 元素。 这是一项安全功能,这样,如果您访问被黑客攻击的网站,您的密码文件就不会被上传给黑客。
http://jira.openqa.org/browse/SEL-63 有详细信息
The normal selenium can't do this because browser security prevents javascript from writing to input=file elements. This is a security feature so that your password file doesnt get uploaded to hackers if you go to a site thats been hacked.
http://jira.openqa.org/browse/SEL-63 has the details