Skip to content

Instantly share code, notes, and snippets.

@aldrienht
Created October 4, 2017 11:23
Show Gist options
  • Save aldrienht/46b2e34f58734a4bd0360f9f53718304 to your computer and use it in GitHub Desktop.
Save aldrienht/46b2e34f58734a4bd0360f9f53718304 to your computer and use it in GitHub Desktop.
Testing With Cucumber and Wicked PDF
#Step-Definition
require 'tempfile'
Then(/^I follow the PDF link "([^"]*)"$/) do |text|
find("a[title='#{text}']").click
temp_pdf = Tempfile.new('pdf')
if Capybara.current_driver == Capybara.javascript_driver
temp_pdf << page.driver.source.force_encoding('UTF-8')
else
temp_pdf << page.driver.response.body.force_encoding('UTF-8')
end
temp_pdf.close
temp_txt = Tempfile.new('txt')
temp_txt.close
`pdftotext -q #{temp_pdf.path} #{temp_txt.path}`
@body = File.read temp_txt.path
@body.gsub!("\f", "\n")
end
Then(/^I should get sucess status$/) do
assert_equal(page.status_code, 200)
end
Then(/^I should get "([^"]*)" content type$/) do |arg1|
page.driver.response.headers['Content-Type'] == "application/pdf"
end
Then(/^I should see "([^"]*)"$/) do |content|
@body.include?(content)
end
#Feature-Scenario
Scenario: Check printable Report PDF
When I follow the PDF link "Report"
And I should get sucess status
And I should get "application/pdf" content type
And I should see "Your-PDF-Content-Here"
...
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment