Skip to content

Commit f344a72

Browse files
authored
Merge pull request #146 from rubycdp/new-release
Compatibility with latest ferrum
2 parents aa6043f + 66760df commit f344a72

5 files changed

Lines changed: 32 additions & 5 deletions

File tree

.github/workflows/tests.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
name: Tests
2-
on: [push]
2+
on:
3+
push:
4+
branches:
5+
- master
6+
pull_request:
37

48
jobs:
59
tests:

cuprite.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Gem::Specification.new do |s|
1919
s.required_ruby_version = ">= 2.3.0"
2020

2121
s.add_runtime_dependency "capybara", ">= 2.1", "< 4"
22-
s.add_runtime_dependency "ferrum", "~> 0.9.0"
22+
s.add_runtime_dependency "ferrum", "~> 0.10.0"
2323

2424
s.add_development_dependency "image_size", "~> 2.0"
2525
s.add_development_dependency "pdf-reader", "~> 2.1"

lib/capybara/cuprite/driver.rb

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,9 @@ def set_proxy(ip, port, type = nil, user = nil, password = nil, bypass = nil)
243243
server = type ? "#{type}=#{ip}:#{port}" : "#{ip}:#{port}"
244244
@options[:browser_options].merge!("proxy-server" => server)
245245
@options[:browser_options].merge!("proxy-bypass-list" => bypass) if bypass
246-
browser.network.authorize(type: :proxy, user: user, password: password)
246+
browser.network.authorize(type: :proxy, user: user, password: password) do |request|
247+
request.continue
248+
end
247249
end
248250

249251
def headers
@@ -296,7 +298,9 @@ def clear_memory_cache
296298
end
297299

298300
def basic_authorize(user, password)
299-
browser.network.authorize(user: user, password: password)
301+
browser.network.authorize(user: user, password: password) do |request|
302+
request.continue
303+
end
300304
end
301305
alias_method :authorize, :basic_authorize
302306

spec/integration/driver_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@ def create_screenshot(file, *args)
657657
expect { @session.visit(url) }
658658
.to raise_error(
659659
Ferrum::StatusError,
660-
%(Request to #{url} failed to reach server, check DNS and/or server status)
660+
%(Request to #{url} failed to reach server, check DNS and server status)
661661
)
662662
end
663663

spec/spec_helper.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
CUPRITE_ROOT = File.expand_path("..", __dir__)
44
$:.unshift(CUPRITE_ROOT + "/lib")
55

6+
require "fileutils"
67
require "bundler/setup"
78
require "rspec"
89

@@ -84,6 +85,8 @@ module TestSessions
8485
end
8586

8687
config.around do |example|
88+
remove_temporary_folders
89+
8790
if ENV["CI"]
8891
session = @session || TestSessions::Cuprite
8992
session.driver.browser.logger.truncate(0)
@@ -106,11 +109,27 @@ def save_exception_aftifacts(browser, meta)
106109
line_number = meta[:line_number]
107110
timestamp = "#{time_now.strftime('%Y-%m-%d-%H-%M-%S.')}#{'%03d' % (time_now.usec/1000).to_i}"
108111

112+
save_exception_log(browser, filename, line_number, timestamp)
113+
save_exception_screenshot(browser, filename, line_number, timestamp)
114+
end
115+
116+
def save_exception_screenshot(browser, filename, line_number, timestamp)
109117
screenshot_name = "screenshot-#{filename}-#{line_number}-#{timestamp}.png"
110118
screenshot_path = "/tmp/cuprite/#{screenshot_name}"
111119
browser.screenshot(path: screenshot_path, full: true)
120+
rescue => e
121+
puts "#{e.class}: #{e.message}"
122+
end
112123

124+
def save_exception_log(browser, filename, line_number, timestamp)
113125
log_name = "logfile-#{filename}-#{line_number}-#{timestamp}.txt"
114126
File.open("/tmp/cuprite/#{log_name}", "wb") { |f| f.write(browser.logger.string) }
127+
rescue => e
128+
puts "#{e.class}: #{e.message}"
129+
end
130+
131+
def remove_temporary_folders
132+
FileUtils.rm_rf(CUPRITE_ROOT + "/screenshots")
133+
FileUtils.rm_rf(CUPRITE_ROOT + "/save_path_tmp")
115134
end
116135
end

0 commit comments

Comments
 (0)