Checking existence of images and favicons with RSpec and Capybara

后端 未结 4 1910
灰色年华
灰色年华 2021-01-12 09:01

Is there a good way to check on existence of images and favicons using rspec and capybara?

I can check on the DOM of favicons and images, but I want to be able to ch

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-12 09:41

    To test for all broken images on a page versus,

    • a specific image,
    • the presence of a selector, or
    • the image availability in the pipeline

    I gather all the images and check a "get" response using the following:

        describe "Check for Images" do
            before { visit page_path }
    
            it "should not have broken images" do
              all_images = page.all('img')
              all_images.each do |img|
                get img[:src]
                expect(response).to be_successful
              end
            end  
        end
    

    Hope that helps.

提交回复
热议问题