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
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 16

def initialize(*args)
  super
  self.render_statuses = {}
  self.dummy_region_provider = RegionProvider.new
  self.dont_get_title = false
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

#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

#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

#base_agent_idObject



53
54
55
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 53

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

#capture_screenshotObject



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

def capture_screenshot
  nil
end

#check(name, target, check_task_uuid) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 37

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)
  match_data.read_target(target_to_check, driver, selector_regions)
  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



57
58
59
60
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 57

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

#default_match_settingsObject



102
103
104
105
106
107
108
109
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 102

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

#dom_urlObject



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

def dom_url
  render_status['domLocation']
end

#ensure_configObject



23
24
25
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 23

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

#get_app_output_with_screenshot(region_provider, last_screenshot) ⇒ Object



128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 128

def get_app_output_with_screenshot(region_provider, last_screenshot)
  # dom_url = ''
  # captured_dom_data = dom_data
  # unless captured_dom_data.empty?
  #   begin
  #     logger.info 'Processing DOM..'
  #     dom_url = server_connector.post_dom_json(captured_dom_data) do |json|
  #       io = StringIO.new
  #       gz = Zlib::GzipWriter.new(io)
  #       gz.write(json.encode('UTF-8'))
  #       gz.close
  #       result = io.string
  #       io.close
  #       result
  #     end
  #     logger.info 'Done'
  #     logger.info dom_url
  #   rescue Applitools::EyesError => e
  #     logger.warn e.message
  #     dom_url = nil
  #   end
  # end
  # logger.info 'Getting screenshot...'
  # screenshot = capture_screenshot
  # logger.info 'Done getting screenshot!'
  region = region_provider.region

  # unless region.empty?
  #   screenshot = screenshot.sub_screenshot region, region_provider.coordinate_type, false
  # end

  # screenshot = yield(screenshot) if block_given?

  # logger.info 'Compressing screenshot...'
  # compress_result = compress_screenshot64 screenshot, last_screenshot
  # logger.info 'Done! Getting title...'
  a_title = title
  # logger.info 'Done!'
  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



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

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

#match_level_keysObject



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

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

#open(driver, browser_info) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/applitools/selenium/visual_grid/eyes_connector.rb', line 28

def open(driver, browser_info)
  self.driver = driver
  self.browser_info = browser_info
  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)


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

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



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

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

#screenshot_urlObject



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

def screenshot_url
  render_status['imageLocation']
end

#selector_regionsObject



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

def selector_regions
  render_status['selectorRegions']
end

#set_viewport_size(*_args) ⇒ Object



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

def set_viewport_size(*_args)
end

#titleObject



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

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



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

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

#viewport_sizeObject



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

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