123456789_123456789_123456789_123456789_123456789_

Module: Capybara::Selenium::Driver::EdgeDriver

Relationships & Source Files
Defined in: lib/capybara/selenium/driver_specializations/edge_driver.rb

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Class Method Details

.extended(base)

[ GitHub ]

  
# File 'lib/capybara/selenium/driver_specializations/edge_driver.rb', line 6

def self.extended(base)
  bridge = base.send(:bridge)
  bridge.extend Capybara::Selenium::IsDisplayed unless bridge.send(:commands, :is_element_displayed)
  base.options[:native_displayed] = false if base.options[:native_displayed].nil?
end

Instance Attribute Details

#clear_all_storage?Boolean (readonly, private)

[ GitHub ]

  
# File 'lib/capybara/selenium/driver_specializations/edge_driver.rb', line 74

def clear_all_storage?
  storage_clears.none? false
end

#download_path=(path) (writeonly)

[ GitHub ]

  
# File 'lib/capybara/selenium/driver_specializations/edge_driver.rb', line 57

def download_path=(path)
  if @browser.respond_to?(:download_path=)
    @browser.download_path = path
  else
    # Not yet implemented in seleniun-webdriver for edge so do it ourselves
    execute_cdp('Page.setDownloadBehavior', behavior: 'allow', downloadPath: path)
  end
end

#uniform_storage_clear?Boolean (readonly, private)

[ GitHub ]

  
# File 'lib/capybara/selenium/driver_specializations/edge_driver.rb', line 78

def uniform_storage_clear?
  storage_clears.uniq { |s| s == false }.length <= 1
end

Instance Method Details

#build_node(native_node, initial_cache = {}) (private)

[ GitHub ]

  
# File 'lib/capybara/selenium/driver_specializations/edge_driver.rb', line 115

def build_node(native_node, initial_cache = {})
  ::Capybara::Selenium::EdgeNode.new(self, native_node, initial_cache)
end

#cdp_unsupported_errors (private)

[ GitHub ]

  
# File 'lib/capybara/selenium/driver_specializations/edge_driver.rb', line 101

def cdp_unsupported_errors
  @cdp_unsupported_errors ||= [Selenium::WebDriver::Error::WebDriverError]
end

#clear_storage (private)

[ GitHub ]

  
# File 'lib/capybara/selenium/driver_specializations/edge_driver.rb', line 86

def clear_storage
  # Edgedriver crashes if attempt to clear storage on about:blank
  url = current_url
  super unless url.nil? || url.start_with?('about:')
end

#delete_all_cookies (private)

[ GitHub ]

  
# File 'lib/capybara/selenium/driver_specializations/edge_driver.rb', line 92

def delete_all_cookies
  return super if edgedriver_version < 75

  execute_cdp('Network.clearBrowserCookies')
rescue *cdp_unsupported_errors
  # If the CDP clear isn't supported do original limited clear
  super
end

#edgedriver_version (private)

[ GitHub ]

  
# File 'lib/capybara/selenium/driver_specializations/edge_driver.rb', line 119

def edgedriver_version
  @edgedriver_version ||= begin
    caps = browser.capabilities
    caps['msedge']&.fetch('msedgedriverVersion', nil).to_f
  end
end

#execute_cdp(cmd, params = {}) (private)

[ GitHub ]

  
# File 'lib/capybara/selenium/driver_specializations/edge_driver.rb', line 105

def execute_cdp(cmd, params = {})
  if browser.respond_to? :execute_cdp
    browser.execute_cdp(cmd, **params)
  else
    args = { cmd: cmd, params: params }
    result = bridge.http.call(:post, "session/#{bridge.session_id}/ms/cdp/execute", args)
    result['value']
  end
end

#fullscreen_window(handle)

[ GitHub ]

  
# File 'lib/capybara/selenium/driver_specializations/edge_driver.rb', line 12

def fullscreen_window(handle)
  return super if edgedriver_version < 75

  within_given_window(handle) do
    super
  rescue NoMethodError => e
    raise unless e.message.include?('full_screen_window')

    result = bridge.http.call(:post, "session/#{bridge.session_id}/window/fullscreen", {})
    result['value']
  end
end

#reset!

[ GitHub ]

  
# File 'lib/capybara/selenium/driver_specializations/edge_driver.rb', line 36

def reset!
  return super if edgedriver_version < 75
  # Use instance variable directly so we avoid starting the browser just to reset the session
  return unless @browser

  switch_to_window(window_handles.first)
  window_handles.slice(1..).each { |win| close_window(win) }

  timer = Capybara::Helpers.timer(expire_in: 10)
  begin
    clear_storage unless uniform_storage_clear?
    @browser.navigate.to('about:blank')
    wait_for_empty_page(timer)
  rescue *unhandled_alert_errors
    accept_unhandled_reset_alert
    retry
  end

  execute_cdp('Storage.clearDataForOrigin', origin: '*', storageTypes: storage_types_to_clear)
end

#resize_window_to(handle, width, height)

[ GitHub ]

  
# File 'lib/capybara/selenium/driver_specializations/edge_driver.rb', line 25

def resize_window_to(handle, width, height)
  super
rescue Selenium::WebDriver::Error::UnknownError => e
  raise unless e.message.include?('failed to change window state')

  # Chromedriver doesn't wait long enough for state to change when coming out of fullscreen
  # and raises unnecessary error. Wait a bit and try again.
  sleep 0.25
  super
end

#storage_clears (private)

[ GitHub ]

  
# File 'lib/capybara/selenium/driver_specializations/edge_driver.rb', line 82

def storage_clears
  options.values_at(:clear_session_storage, :clear_local_storage)
end

#storage_types_to_clear (private)

[ GitHub ]

  
# File 'lib/capybara/selenium/driver_specializations/edge_driver.rb', line 68

def storage_types_to_clear
  types = ['cookies']
  types << 'local_storage' if clear_all_storage?
  types.join(',')
end