Class: Applitools::Selenium::EyesConnector

Inherits:
EyesBase
  • Object
show all
Defined in:
lib/applitools/selenium/visual_grid/eyes_connector.rb

Defined Under Namespace

Classes: RegionProvider

Constant Summary collapse

USE_DEFAULT_MATCH_TIMEOUT =
-1

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ EyesConnector

Returns a new instance of EyesConnector.



16
17
18
19
20
21
22
23
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 16

def initialize(*args)
  options = Applitools::Utils.extract_options!(args)
  super
  self.render_statuses = {}
  self.dummy_region_provider = RegionProvider.new
  self.dont_get_title = false
  self.driver_lock = options[:driver_lock]
end

Instance Attribute Details

#browser_infoObject

Returns the value of attribute browser_info.



6
7
8
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 6

def browser_info
  @browser_info
end

#current_uuidObject

Returns the value of attribute current_uuid.



6
7
8
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 6

def current_uuid
  @current_uuid
end

#device_nameObject

Returns the value of attribute device_name.



6
7
8
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 6

def device_name
  @device_name
end

#dont_get_titleObject

Returns the value of attribute dont_get_title.



6
7
8
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 6

def dont_get_title
  @dont_get_title
end

#driverObject

Returns the value of attribute driver.



6
7
8
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 6

def driver
  @driver
end

#driver_lockObject

Returns the value of attribute driver_lock.



6
7
8
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 6

def driver_lock
  @driver_lock
end

#dummy_region_providerObject

Returns the value of attribute dummy_region_provider.



6
7
8
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 6

def dummy_region_provider
  @dummy_region_provider
end

#render_statusesObject

Returns the value of attribute render_statuses.



6
7
8
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 6

def render_statuses
  @render_statuses
end

#test_resultObject

Returns the value of attribute test_result.



6
7
8
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 6

def test_result
  @test_result
end

Instance Method Details

#app_environmentObject



122
123
124
125
126
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 122

def app_environment
  super.tap do |env|
    env.device_info = device_name
  end
end

#base_agent_idObject



62
63
64
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 62

def base_agent_id
  "eyes.selenium.visualgrid.ruby/#{Applitools::VERSION}"
end

#capture_screenshotObject



71
72
73
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 71

def capture_screenshot
  nil
end

#check(name, target, check_task_uuid) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 40

def check(name, target, check_task_uuid)
  self.current_uuid = check_task_uuid
  target_to_check = target.finalize
  timeout = target_to_check.options[:timeout] || USE_DEFAULT_MATCH_TIMEOUT

  match_data = Applitools::Selenium::VgMatchWindowData.new
  match_data.tag = name
  update_default_settings(match_data)
  begin
    match_data.read_target(target_to_check, driver, selector_regions)
  rescue Applitools::Selenium::VgMatchWindowData::RegionCoordinatesError => e
    logger.error "Error retrieving coordinates for region #{e.region}"
    logger.error e.message
  end

  check_result = check_window_base(
      dummy_region_provider, timeout, match_data
  )
  self.current_uuid = nil
  check_result
end

#close(throw_exception = true, be_silent = false) ⇒ Object



66
67
68
69
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 66

def close(throw_exception = true, be_silent = false)
  self.current_uuid = nil
  self.test_result = super
end

#default_match_settingsObject



111
112
113
114
115
116
117
118
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 111

def default_match_settings
  {
      match_level: match_level,
      exact: exact,
      scale: server_scale,
      remainder: server_remainder
  }
end

#dom_urlObject



89
90
91
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 89

def dom_url
  render_status['domLocation']
end

#ensure_configObject



25
26
27
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 25

def ensure_config
  self.config = Applitools::Selenium::Configuration.new
end

#get_app_output_with_screenshot(region_provider, last_screenshot) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 142

def get_app_output_with_screenshot(region_provider, last_screenshot)
  region = region_provider.region
  a_title = title
  Applitools::AppOutputWithScreenshot.new(
    Applitools::AppOutput.new(a_title, '').tap do |o|
      o.location = region.location unless region.empty?
      o.dom_url = dom_url
      o.screenshot_url = screenshot_url if respond_to?(:screenshot_url) && !screenshot_url.nil?
    end,
    nil,
    true
  )
end

#inferred_environmentObject



107
108
109
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 107

def inferred_environment
  "useragent: #{render_status['userAgent']}"
end

#match_level_keysObject



97
98
99
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 97

def match_level_keys
  %w(match_level exact scale remainder).map(&:to_sym)
end

#open(driver, browser_info) ⇒ Object



30
31
32
33
34
35
36
37
38
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 30

def open(driver, browser_info)
  self.driver = driver
  self.browser_info = browser_info
  self.device_name = browser_info && browser_info.emulation_info && browser_info.emulation_info.device_name
  logger.info "opening EyesConnector for #{config.short_description} with viewport size: #{browser_info}"
  config.viewport_size = browser_info.viewport_size
  open_base
  # ensure_running_session
end

#render_statusObject

Raises:

  • (Applitools::EyesError)


79
80
81
82
83
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 79

def render_status
  status = render_statuses[current_uuid]
  raise Applitools::EyesError, 'Got empty render status!' if status.nil? || !status.is_a?(Hash) || status.keys.empty?
  status
end

#render_status_for_task(uuid, status) ⇒ Object



75
76
77
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 75

def render_status_for_task(uuid, status)
  render_statuses[uuid] = status
end

#screenshot_urlObject



85
86
87
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 85

def screenshot_url
  render_status['imageLocation']
end

#selector_regionsObject



93
94
95
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 93

def selector_regions
  render_status['selectorRegions']
end

#set_viewport_size(*_args) ⇒ Object



120
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 120

def set_viewport_size(*_args); end

#titleObject



134
135
136
137
138
139
140
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 134

def title
  return driver.title unless dont_get_title
rescue StandardError => e
  logger.warn "failed (#{e.message})"
  self.dont_get_title = false
  ''
end

#update_default_settings(match_data) ⇒ Object



101
102
103
104
105
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 101

def update_default_settings(match_data)
  match_level_keys.each do |k|
    match_data.send("#{k}=", default_match_settings[k])
  end
end

#viewport_sizeObject



128
129
130
131
132
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 128

def viewport_size
  status = render_statuses[render_statuses.keys.first]
  size = status['deviceSize']
  Applitools::RectangleSize.new(size['width'], size['height'])
end