使用RSpec和Capybara检查图像和图标的存在

Jas*_*Kim 7 rspec ruby-on-rails capybara

有没有一种很好的方法来检查使用rspec和水豚的图像和favicons的存在?

我可以查看favicon和图像的DOM,但我希望能够检查这些图像是否也加载.这对rspec和水豚有可能吗?

Bil*_*han 6

describe "check images and favicon" do
  before { visit "url/to/check")

  it "should have the images" do
    page.should have_css('img', text: "image1.jpg")

  it "should have the favicon" do
    page.should have_xpath("/html/head/link[@href='favicon.ico']"
  end 
end
Run Code Online (Sandbox Code Playgroud)

  • 仅存在选择器是不够的,图像可能会损坏 (2认同)