Skip to content

Commit b8826d9

Browse files
authored
Merge pull request #254 from nickhammond/spec/download-file
Add a simple download spec and mention save_path in the readme
2 parents 2c087c5 + 3a0e352 commit b8826d9

File tree

3 files changed

+27
-0
lines changed

3 files changed

+27
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ Ferrum::Browser.new(options)
181181
over the web socket, in bytes. Defaults to 64MB. Incoming messages larger
182182
than this will cause a `Ferrum::DeadBrowserError`.
183183
* `:proxy` (Hash) - Specify proxy settings, [read more](https://github.com/rubycdp/ferrum#proxy)
184+
* `:save_path` (String) - Path to save screenshots, PDF, mhtml, and attachment requests
184185

185186

186187
## Navigation

spec/download_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# frozen_string_literal: true
2+
3+
module Ferrum
4+
describe Browser do
5+
context "download support" do
6+
let(:browser) do
7+
Ferrum::Browser.new(
8+
base_url: Ferrum::Server.server.base_url,
9+
save_path: "/tmp/ferrum"
10+
)
11+
end
12+
13+
it "saves an attachment" do
14+
browser.go_to("/attachment.pdf")
15+
16+
expect(File.exist?("/tmp/ferrum/attachment.pdf")).to be true
17+
end
18+
end
19+
end
20+
end

spec/support/application.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,12 @@ def initialize(something, message)
182182
"This, is, comma, separated"
183183
end
184184

185+
get "/attachment.pdf" do
186+
path = "/tmp/ferrum/attachment.pdf"
187+
FileUtils.touch(path)
188+
attachment(path, :attachment)
189+
end
190+
185191
get "/:view" do |view|
186192
erb view.to_sym, locals: { referrer: request.referrer }
187193
end

0 commit comments

Comments
 (0)