0

I have a web application in Ruby on Rails which uses the wicked_pdf gem to render a PDF. A week ago the PDF rendering failed and my test suite running didn't show because a test was missing. The opened PDF above opens in a new tab so I want to test the PDF opening itself to be correctly rendering.

I actually am able to run cucumber tests for the click on the PDF link (which renders in a new tab) and double check that on the initial page shows a certain phrase. But if I want to check Then I should see "string_on_pdf" this fails. Probably the test suite is running the code not in the new tab with the PDF opened.

So my questions:

  1. Is there a way in cucumber integration test to switch tabs to the PDF?
  2. Can I then test for content with Then I should see on the PDF?

As requested in the comments I am adding the controller action of the show action:

def show
    load_out_invoice
    if @out_invoice.nil?
      redirect_to not_found_path
    else
      @title = "#{t('titles.out_invoices.show')} #{@out_invoice.number}"
      respond_to do |format|
        format.html
        format.pdf do
          @current_user = current_user
          @out_invoice.archived = true if params[:temporary_archived]=="1"
          render template: "home/out_invoices/pdf.html.erb",
                 pdf: @out_invoice.pdf_name,
                 encoding: 'utf-8'
        end
      end
    end
  end
5
  • stackoverflow.com/questions/53099223/…, stackoverflow.com/questions/59585872/…, or stackoverflow.com/questions/41480782/pdf-reader-cucumber-ruby might help. Many people seem to recommend the pdf-inspector gem provided by prawn. If you are rendering directly to the browser, e.g. send_data you might want to refactor, so that you can directly test the "render to string" output. Commented Sep 15 at 20:35
  • 1
    Please note your question is incomplete since we have no means of determining how you are generating or distributing the PDF. Commented Sep 15 at 20:37
  • @engineersmnky what exactly do you mean? I have a rails application using the wicked_pdf gem for serving pdfs directly from a controller action because format is specified ".pdf" Commented Sep 17 at 22:15
  • I mean add the controller action to the post. Show us how you are serving the PDF. You said "if I want to check Then I should see "string_on_pdf" this fails", you should add the failed step. A MRE is invaluable. Commented Sep 18 at 2:07
  • I think now I understand @enigineersmnky. Basically an attribute of the object being rendered on PDF has value "string_on_pdf" which should get rendered normally on the pdf. I will also look at pdf-inspector. Thanks for the tip! Commented Oct 14 at 9:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.