Quantcast
Channel: Active questions tagged selenium - Stack Overflow
Viewing all articles
Browse latest Browse all 99411

How to test the content of a PDF file using capybara

$
0
0

I'm trying to access http://www.orimi.com/pdf-test.pdf to test if "PDF Test File" exists.

This is my code:

it 'pdf test' do
        visit 'http://www.orimi.com/pdf-test.pdf'
        puts page.title
        sleep 5
        convert_pdf_to_page
        expect(page).to have_content 'PDF Test File'
end

def convert_pdf_to_page
        temp_pdf = Tempfile.new('pdf')
        temp_pdf << page.source.force_encoding('UTF-8')
        reader = PDF::Reader.new(temp_pdf)
        pdf_text = reader.pages.map(&:text)
        temp_pdf.close
        page.driver.response.instance_variable_set('@body', pdf_text)
end

But I got:

PDF::Reader::MalformedPDFError: PDF does not contain EOF marker

I searched and I found that the problem can be the PDF file. I checked the temp_pdf variable and there is just HTML with a empty body.

Is there something wrong in my code?


Viewing all articles
Browse latest Browse all 99411

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>