module Capybara::Screenshot::BrowserHelpers
Constants
- FIND_ACTIVE_ELEMENT_SCRIPT
- GET_BOUNDING_CLIENT_RECT_SCRIPT
- HIDE_CARET_SCRIPT
- IMAGE_WAIT_SCRIPT
Public Class Methods
Source
# File lib/capybara/screenshot/diff/browser_helpers.rb, line 87 def self.all_visible_regions_for(selector) BrowserHelpers.session.all(selector, visible: true).map(&method(:region_for)) end
Source
# File lib/capybara/screenshot/diff/browser_helpers.rb, line 74 def self.blur_from_focused_element session.evaluate_script(FIND_ACTIVE_ELEMENT_SCRIPT) end
Source
# File lib/capybara/screenshot/diff/browser_helpers.rb, line 31 def self.bounds_for_css(*css_selectors) css_selectors.reduce([]) do |regions, selector| regions.concat(all_visible_regions_for(selector)) end end
Source
# File lib/capybara/screenshot/diff/browser_helpers.rb, line 103 def self.current_capybara_driver_class session.driver.class end
Source
# File lib/capybara/screenshot/diff/browser_helpers.rb, line 59 def self.hide_caret session.execute_script(HIDE_CARET_SCRIPT) end
Source
# File lib/capybara/screenshot/diff/browser_helpers.rb, line 99 def self.pending_image_to_load BrowserHelpers.session.evaluate_script(IMAGE_WAIT_SCRIPT) end
Source
# File lib/capybara/screenshot/diff/browser_helpers.rb, line 91 def self.region_for(element) element.evaluate_script(GET_BOUNDING_CLIENT_RECT_SCRIPT).map { |point| point.negative? ? 0 : point.ceil.to_i } end
Source
# File lib/capybara/screenshot/diff/browser_helpers.rb, line 14 def self.resize_to(window_size) if session.driver.respond_to?(:resize) session.driver.resize(*window_size) elsif BrowserHelpers.selenium? session.driver.browser.manage.window.resize_to(*window_size) end end
Source
# File lib/capybara/screenshot/diff/browser_helpers.rb, line 8 def self.resize_window_if_needed if ::Capybara::Screenshot.respond_to?(:window_size) && ::Capybara::Screenshot.window_size resize_to(::Capybara::Screenshot.window_size) end end
Source
# File lib/capybara/screenshot/diff/browser_helpers.rb, line 22 def self.selenium? current_capybara_driver_class <= Capybara::Selenium::Driver end
Source
# File lib/capybara/screenshot/diff/browser_helpers.rb, line 95 def self.session Capybara.current_session end
Source
# File lib/capybara/screenshot/diff/browser_helpers.rb, line 26 def self.window_size_is_wrong?(expected_window_size = nil) selenium? && expected_window_size && session.driver.browser.manage.window.size != ::Selenium::WebDriver::Dimension.new(*expected_window_size) end