如何找到由 Dragonfly with Cucumber/Capybara 生成的图像?

发布于 2024-10-22 20:06:29 字数 977 浏览 0 评论 0原文

在对 如何在带有 Cucumber/Capybara 的页面上查找图像,有人问:

我似乎不知道如何得到这个 使用生成的 URL 蜻蜓。它们看起来像这样: /media/BAh_some_long_string_AwIw/12_11_52_810_5x5.jpg?s=7e360000,其中 5x5.jpg 是我的文件名。我已经 尝试过类似的东西: //img[@src="/media//#{image}?s=*"] 但它不起作用。有什么建议吗? – Ramon Tayag 2 月 25 日 4:18

我遇到了类似的问题,甚至更糟 - 就我而言,生成的图像路径甚至不包含(jpg | png | gif)文件名,它们只有这些非常长的ID:(

<img src="/media/BAhbB1sHOgZmSSIdNGQ4MTEyOGU3ZjViZmQwZTQ4MDAwMDAyBjoGRVRbCDoGcDoKdGh1bWJJIg0yMDB4MjAwIwY7BlQ" />

使用蜻蜓与mongo / gridfs)

这些路径渲染得很好,但我不知道如何找到他们在黄瓜/水豚步骤中:P

有什么想法吗?我查看了 Dragonfly 的功能,但它们只测试图像的渲染本身,而不检测它是否存在于 html 页面中。

In the comments to the solution for How do I find an image on a page with Cucumber/Capybara, somebody asked:

I can't seem to figure how to get this
to work with URLs generated by
Dragonfly. They look like this:
/media/BAh_some_long_string_AwIw/12_11_52_810_5x5.jpg?s=7e360000, where 5x5.jpg is my file name. I've
tried something like:
//img[@src="/media//#{image}?s=*"]
but it doesn't work. Got any tips? – Ramon Tayag Feb 25 at 4:18

I have a similar problem, only worse - in my case, the generated image paths don't even include a (jpg|png|gif) file name, they only have these really long ids:

<img src="/media/BAhbB1sHOgZmSSIdNGQ4MTEyOGU3ZjViZmQwZTQ4MDAwMDAyBjoGRVRbCDoGcDoKdGh1bWJJIg0yMDB4MjAwIwY7BlQ" />

(Using dragonfly with mongo/gridfs)

These paths get rendered alright, but I can't figure out how to find them in a Cucumber/Capybara step :P

Any ideas? I looked at the Dragonfly's features, but they only test the rendering of the image itself, without detecting it's existence within an html page.

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

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

发布评论

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

评论(1

七婞 2024-10-29 20:06:29

与 Dragonfly 的作者交谈之后回答我自己的问题(他正在努力使这变得更容易):

#route
match '/media/:dragonfly/:file_name', :to => Dragonfly[:images]  

#model
class Store
  include MongoMapper::Document
  key :photo_uid, String
  key :photo_name, String
  image_accessor :photo
end

#view
<%= image_tag @store.photo.thumb('274x207#').url(:suffix => "/#{@store.photo_name}") if @store.photo %>

#cucumber
Then I should see the image "my_photo.png"

Then /^I should see the image "(.+)"$/ do |image|  
  page.should have_xpath("//img[contains(@src, \"#{image}\")]")
end

关键是将 [attachment]_name 字段添加到模型中,Dragonfly 会自动填充该字段,然后将其作为后缀传递给 url()。除了生成的蜻蜓标识符之外,路由还需要允许 :file_name 参数。

Answering my own question, after talking to Dragonfly's author (he's working on making this easier):

#route
match '/media/:dragonfly/:file_name', :to => Dragonfly[:images]  

#model
class Store
  include MongoMapper::Document
  key :photo_uid, String
  key :photo_name, String
  image_accessor :photo
end

#view
<%= image_tag @store.photo.thumb('274x207#').url(:suffix => "/#{@store.photo_name}") if @store.photo %>

#cucumber
Then I should see the image "my_photo.png"

Then /^I should see the image "(.+)"$/ do |image|  
  page.should have_xpath("//img[contains(@src, \"#{image}\")]")
end

The key is adding an [attachment]_name field to the model, which Dragonfly populates automatically, and then passing it on as a suffix to url(). And the routes needs to allow for a :file_name param besides the generated dragonfly identifier.

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