在 Rails 3 上使用 Cucumber 测试 uploadify

发布于 2024-10-09 01:55:46 字数 142 浏览 0 评论 0原文

我想要在 ruby​​ on Rails 3 上进行上传测试的黄瓜测试。我曾尝试单击水豚的上传按钮,但因为它既不是按钮也不是链接。此外,它隐藏了 text_field,因此我无法编写“当我用“text.txt”填写“上传”时”。如果有人解决了这个问题,请在这里提供帮助。

I want cucumber test for uploadify on ruby on rails 3. I had tried to click on the upload button from capybara but as it is neither button nor link. Furthermore, it is hiding the text_field so I cannot write "When I fill in "upload" with "text.txt"". If any one has solved this problem, please help is needed here.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

提笔落墨 2024-10-16 01:55:46

编写上传文件

When /^(?:|I)attach the file "([^"]*)" to "([^"]*)"$/ do |path, field|
  type = path.split(".")[1]
  case type
  when "jpg"
    type = "image/jpg"
  when "png"
    type = "image/png"
  when "gif"
    type = "image/gif"
  end
  attach_file(field, path, type)
end

When /^I attach the "(.*)" file at "(.*)" to "(.*)"$/ do |type, path, field|
 attach_file(field,path,type)
end

Cucumber 步骤的自定义步骤,例如

当我将文件“/images/back.gif”附加到“data_input”时

Write custom step for uploading a file

When /^(?:|I)attach the file "([^"]*)" to "([^"]*)"$/ do |path, field|
  type = path.split(".")[1]
  case type
  when "jpg"
    type = "image/jpg"
  when "png"
    type = "image/png"
  when "gif"
    type = "image/gif"
  end
  attach_file(field, path, type)
end

When /^I attach the "(.*)" file at "(.*)" to "(.*)"$/ do |type, path, field|
 attach_file(field,path,type)
end

Cucumber Step like

When I attach the file "/images/back.gif" to "data_input"

囚我心虐我身 2024-10-16 01:55:46

您需要编写一个自定义步骤来上传文件,

When /^I upload a file$/ do
    attach_file(:image, <path-to-file>)
end 

其中 image 是用于获取要上传的文件的 html 元素的名称。

You would need to write a custom step for uploading a file

When /^I upload a file$/ do
    attach_file(:image, <path-to-file>)
end 

Where image is the name of the html element for getting the file to be uploaded.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文