browsed 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 22709958a9bfb3df2bcd7c1705fab8b8142f684cd9520c87584ac152dec8685a
4
- data.tar.gz: ceafaf076006cd6b2a19677416f61337bcd016c6093fcc956ad4fb94d6a374e6
3
+ metadata.gz: 61e83765b6257c39cd97be1c3764a20bb20e90b6ce602c94d693b0fb4444bf64
4
+ data.tar.gz: 8f747af9a52257cd1a05aecfddbd81fc714e76253472eba5ef7724a6dce1e10f
5
5
  SHA512:
6
- metadata.gz: 4e138bccb76f8fa621d9b911a695b869204669de742f681c8617ca19a9b68fd50e9e7401ba537498aae19c966981b4a5eae85da8226e7e3ab474cedff8c70557
7
- data.tar.gz: 365750f46aa4e252ba81962e82bc667277926fbcd81f864d8e1bdf594b00dcf55e116c10a6b7bef2695520f34410dbb4fe5e64a6f09f6d901cc8ad560366fbfd
6
+ metadata.gz: 666a4dd2ace58b39da9b7132493c0f64dc605fb50de3db3363b21f18caaa643be3cc33321c6ce5e94c372735e998e8ba611262a683591351f3512617f125ddee
7
+ data.tar.gz: 4b191391235827932b9b8e16942802757424bfb77f25b0a9076243ba8fa520f9da87a3faf293c29e321be0c8e64503d375fd5901344c480e5e744b8739837399
@@ -4,17 +4,17 @@ module Browsed
4
4
  private
5
5
  def register_chrome_driver(options: {}, timeout: 60, debug: false)
6
6
  headless = options.fetch(:headless, false)
7
- width = option.fetch(:width, 1920)
8
- height = options.fetch(:height, 1080)
7
+ resolution = options.fetch(:resolution, [1366,768])
9
8
  profile = Selenium::WebDriver::Chrome::Profile.new
10
9
 
11
10
  profile["user-agent"] = self.user_agent unless self.user_agent.to_s.empty?
12
11
 
13
12
  proxy_options = chrome_proxy_options
14
13
  capabilities = !proxy_options.nil? ? Selenium::WebDriver::Remote::Capabilities.chrome(proxy: proxy_options) : {}
15
- args = %W(disable-popup-blocking window-size=#{height},#{width})
16
- args = args | %w(headless disable-gpu)
17
- raise args.inspect
14
+ args = %w(disable-popup-blocking)
15
+ args = args | %W(window-size=#{resolution.first},#{resolution.last}) if resolution && resolution.any? && resolution.size.eql?(2)
16
+ args = args | %w(headless disable-gpu) if headless
17
+
18
18
  options = Selenium::WebDriver::Chrome::Options.new(profile: profile, args: args)
19
19
 
20
20
  Capybara.register_driver self.driver do |app|
@@ -72,11 +72,16 @@ module Browsed
72
72
  def resize!(res = nil)
73
73
  res ||= self.resolution
74
74
 
75
- if res && res.size.eql?(2) && !self.driver.eql?(:chrome) && !self.driver.eql?(:poltergeist) # Resolutions for Chrome & Poltergeist are set in the driver
75
+ if res && res.size.eql?(2) && resizable_browser?(self.driver) # Resolutions for Chrome & Poltergeist are set in the driver
76
76
  self.session.current_window.resize_to(res.first, res.last) # [width, height]
77
77
  end
78
78
  end
79
79
 
80
+ def resizable_browser?(driver)
81
+ non_resizable = [:poltergeist, :selenium_chrome, :selenium_chrome_headless]
82
+ !non_resizable.include?(driver.to_sym)
83
+ end
84
+
80
85
  def reset_session!
81
86
  self.session.reset_session!
82
87
  end
@@ -104,18 +109,16 @@ module Browsed
104
109
  def register_driver!(options = {})
105
110
  if poltergeist?
106
111
  register_poltergeist_driver(options: options)
107
- elsif selenium?
108
- if firefox_browser?
109
- register_firefox_driver(options: options)
110
- elsif firefox_headless_browser?
111
- register_firefox_driver(options: options.merge(headless: true))
112
- elsif chrome_browser?
113
- self.driver = :selenium_chrome
114
- register_chrome_driver(options: options)
115
- elsif chrome_headless_browser?
116
- self.driver = :selenium_chrome_headless
117
- register_chrome_driver(options: options.merge(headless: true))
118
- end
112
+ elsif firefox_browser?
113
+ register_firefox_driver(options: options)
114
+ elsif firefox_headless_browser?
115
+ register_firefox_driver(options: options.merge(headless: true))
116
+ elsif chrome_browser?
117
+ self.driver = :selenium_chrome
118
+ register_chrome_driver(options: options.merge(resolution: self.resolution))
119
+ elsif chrome_headless_browser?
120
+ self.driver = :selenium_chrome_headless
121
+ register_chrome_driver(options: options.merge(resolution: self.resolution, headless: true))
119
122
  end
120
123
  end
121
124
 
@@ -1,3 +1,3 @@
1
1
  module Browsed
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: browsed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian