Class: Applitools::Selenium::SeleniumEyes

Inherits:
EyesBase
  • Object
show all
Extended by:
Forwardable
Includes:
Concerns::SeleniumEyes
Defined in:
lib/applitools/selenium/selenium_eyes.rb

Overview

The main API gateway for the SDK

Constant Summary collapse

DEFAULT_DEVICE_PIXEL_RATIO =

The pixel ratio will be used if detection of device pixel ratio is failed

1
DEFAULT_WAIT_BEFORE_SCREENSHOTS =

Seconds

0.1
DEFAULT_STITCHING_OVERLAP =

Pixels

0

Constants included from Concerns::SeleniumEyes

Concerns::SeleniumEyes::USE_DEFAULT_MATCH_TIMEOUT

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Concerns::SeleniumEyes

#check_frame, #check_region, #check_region_in_frame, #check_window, #test

Constructor Details

#initialize(*args) ⇒ SeleniumEyes

Creates a new (possibly disabled) Eyes instance that interacts with the Eyes Server at the specified url.

Parameters:

  • server_url

    The Eyes Server URL.



85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/applitools/selenium/selenium_eyes.rb', line 85

def initialize(*args)
  ensure_config
  super
  self.runner = Applitools::ClassicRunner.new unless runner
  self.base_agent_id = "eyes.selenium.ruby/#{Applitools::VERSION}".freeze
  self.check_frame_or_element = false
  self.region_to_check = nil
  # self.force_full_page_screenshot = false
  self.dont_get_title = false
  self.device_pixel_ratio = UNKNOWN_DEVICE_PIXEL_RATIO
  self.stitch_mode = Applitools::STITCH_MODE[:scroll]
  self.wait_before_screenshots = DEFAULT_WAIT_BEFORE_SCREENSHOTS
  self.region_visibility_strategy = MoveToRegionVisibilityStrategy.new
  self.debug_screenshots = false
  self.debug_screenshot_provider = Applitools::DebugScreenshotProvider.new
                                                                      .tag_access { tag_for_debug }
                                                                      .debug_flag_access { debug_screenshots }
  self.disable_horizontal_scrolling = false
  self.disable_vertical_scrolling = false
  self.explicit_entire_size = nil
  self.force_driver_resolution_as_viewport_size = false
  self.stitching_overlap = DEFAULT_STITCHING_OVERLAP
  self.full_page_capture_algorithm_left_top_offset = Applitools::Location::TOP_LEFT
  self.send_dom = true
  self.use_dom = false
  self.enable_patterns = false
  self.prevent_dom_processing = false
  self.utils = Applitools::Utils::EyesSeleniumUtils
end

Instance Attribute Details

#base_agent_idObject

Returns the value of attribute base_agent_id.



70
71
72
# File 'lib/applitools/selenium/selenium_eyes.rb', line 70

def base_agent_id
  @base_agent_id
end

#configObject

Returns the value of attribute config.



70
71
72
# File 'lib/applitools/selenium/selenium_eyes.rb', line 70

def config
  @config
end

#debug_screenshot_providerObject

Returns the value of attribute debug_screenshot_provider.



70
71
72
# File 'lib/applitools/selenium/selenium_eyes.rb', line 70

def debug_screenshot_provider
  @debug_screenshot_provider
end

#debug_screenshotsObject

Returns the value of attribute debug_screenshots.



70
71
72
# File 'lib/applitools/selenium/selenium_eyes.rb', line 70

def debug_screenshots
  @debug_screenshots
end

#disable_horizontal_scrollingObject

Returns the value of attribute disable_horizontal_scrolling.



70
71
72
# File 'lib/applitools/selenium/selenium_eyes.rb', line 70

def disable_horizontal_scrolling
  @disable_horizontal_scrolling
end

#disable_vertical_scrollingObject

Returns the value of attribute disable_vertical_scrolling.



70
71
72
# File 'lib/applitools/selenium/selenium_eyes.rb', line 70

def disable_vertical_scrolling
  @disable_vertical_scrolling
end

#driverObject

Returns the value of attribute driver.



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

def driver
  @driver
end

#enable_patternsObject

Returns the value of attribute enable_patterns.



70
71
72
# File 'lib/applitools/selenium/selenium_eyes.rb', line 70

def enable_patterns
  @enable_patterns
end

#explicit_entire_sizeObject

Returns the value of attribute explicit_entire_size.



70
71
72
# File 'lib/applitools/selenium/selenium_eyes.rb', line 70

def explicit_entire_size
  @explicit_entire_size
end

#force_full_page_screenshotboolean

Forces a full page screenshot (by scrolling and stitching) if the browser only supports viewport screenshots.

Returns:

  • (boolean)

    force full page screenshot flag



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

attr_accessor :base_agent_id, :force_full_page_screenshot, :hide_scrollbars,
:wait_before_screenshots, :debug_screenshots, :stitch_mode, :disable_horizontal_scrolling,
:disable_vertical_scrolling, :explicit_entire_size, :debug_screenshot_provider, :stitching_overlap,
:full_page_capture_algorithm_left_top_offset, :send_dom, :use_dom, :enable_patterns,
:utils,
:config

#full_page_capture_algorithm_left_top_offsetObject

Returns the value of attribute full_page_capture_algorithm_left_top_offset.



70
71
72
# File 'lib/applitools/selenium/selenium_eyes.rb', line 70

def full_page_capture_algorithm_left_top_offset
  @full_page_capture_algorithm_left_top_offset
end

#hide_scrollbarsboolean

Turns on/off hiding scrollbars before taking a screenshot

Returns:

  • (boolean)

    hide_scrollbars flag



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

attr_accessor :base_agent_id, :force_full_page_screenshot, :hide_scrollbars,
:wait_before_screenshots, :debug_screenshots, :stitch_mode, :disable_horizontal_scrolling,
:disable_vertical_scrolling, :explicit_entire_size, :debug_screenshot_provider, :stitching_overlap,
:full_page_capture_algorithm_left_top_offset, :send_dom, :use_dom, :enable_patterns,
:utils,
:config

#send_domObject

Returns the value of attribute send_dom.



70
71
72
# File 'lib/applitools/selenium/selenium_eyes.rb', line 70

def send_dom
  @send_dom
end

#stitch_modeboolean

May be set to :CSS or :SCROLL (:SCROLL is default). When :CSS - SDK will use CSS transitions to perform scrolling, otherwise it will use Javascript window.scroll_to() function for scrolling purposes

Returns:

  • (boolean)

    stitch_mode (:CSS or :SCROLL)



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

attr_accessor :base_agent_id, :force_full_page_screenshot, :hide_scrollbars,
:wait_before_screenshots, :debug_screenshots, :stitch_mode, :disable_horizontal_scrolling,
:disable_vertical_scrolling, :explicit_entire_size, :debug_screenshot_provider, :stitching_overlap,
:full_page_capture_algorithm_left_top_offset, :send_dom, :use_dom, :enable_patterns,
:utils,
:config

#stitching_overlapObject

Returns the value of attribute stitching_overlap.



70
71
72
# File 'lib/applitools/selenium/selenium_eyes.rb', line 70

def stitching_overlap
  @stitching_overlap
end

#use_domObject

Returns the value of attribute use_dom.



70
71
72
# File 'lib/applitools/selenium/selenium_eyes.rb', line 70

def use_dom
  @use_dom
end

#utilsObject

Returns the value of attribute utils.



70
71
72
# File 'lib/applitools/selenium/selenium_eyes.rb', line 70

def utils
  @utils
end

#wait_before_screenshotsFloat

Sets the time to wait just before taking a screenshot (e.g., to allow positioning to stabilize when performing a full page stitching).

Returns:

  • (Float)

    The time to wait (Seconds). Values smaller or equal to 0, will cause the default value to be used.



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

attr_accessor :base_agent_id, :force_full_page_screenshot, :hide_scrollbars,
:wait_before_screenshots, :debug_screenshots, :stitch_mode, :disable_horizontal_scrolling,
:disable_vertical_scrolling, :explicit_entire_size, :debug_screenshot_provider, :stitching_overlap,
:full_page_capture_algorithm_left_top_offset, :send_dom, :use_dom, :enable_patterns,
:utils,
:config

Class Method Details

.environment_sdkObject



115
116
117
118
119
120
# File 'lib/applitools/selenium/selenium_eyes.rb', line 115

def self.environment_sdk
  {
    name: :eyes_selenium,
    currentVersion: Applitools::EyesSelenium::VERSION
  }
end

.eyes_driver(driver, eyes = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/applitools/selenium/selenium_eyes.rb', line 22

def eyes_driver(driver, eyes = nil)
  if driver.respond_to? :driver_for_eyes
    driver.driver_for_eyes eyes
  else
    if !driver.is_a?(Applitools::Selenium::Driver)
      Applitools::EyesLogger.warn("Unrecognized driver type: (#{driver.class.name})!")
      is_mobile_device = driver.respond_to?(:capabilities) && driver.capabilities['platformName']
      Applitools::Selenium::Driver.new(eyes, driver: driver, is_mobile_device: is_mobile_device)
    else
      driver
    end
  end
end

.set_viewport_size(driver, viewport_size) ⇒ Object

Set the viewport size.

Parameters:



40
41
42
# File 'lib/applitools/selenium/selenium_eyes.rb', line 40

def set_viewport_size(driver, viewport_size)
  super
end

Instance Method Details

#abort_asyncObject



237
238
239
# File 'lib/applitools/selenium/selenium_eyes.rb', line 237

def abort_async
  abort
end

#add_mouse_trigger(mouse_action, element) ⇒ Object



335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
# File 'lib/applitools/selenium/selenium_eyes.rb', line 335

def add_mouse_trigger(mouse_action, element)
  if disabled?
    logger.info "Ignoring #{mouse_action} (disabled)"
    return
  end

  if element.is_a? Hash
    return add_mouse_trigger_by_region_and_location(mouse_action, element[:region], element[:location]) if
        element.key?(:location) && element.key?(:region)
    raise Applitools::EyesIllegalArgument.new 'Element[] doesn\'t contain required keys!'
  end

  Applitools::ArgumentGuard.not_nil element, 'element'
  Applitools::ArgumentGuard.is_a? element, 'element', Applitools::Selenium::Element

  pl = element.location
  ds = element.size

  element_region = Applitools::Region.new(pl.x, pl.y, ds.width, ds.height)

  unless last_screenshot
    logger.info "Ignoring #{mouse_action} (no screenshot)"
    return
  end

  unless driver.frame_chain.same_frame_chain? last_screenshot.frame_chain
    logger.info "Ignoring #{mouse_action} (different_frame)"
    return
  end

  add_mouse_trigger_base(mouse_action, element_region, element_region.middle_offset)
end

#add_mouse_trigger_by_region_and_location(mouse_action, control, cursor) ⇒ Object

control - Region cursor - Location



370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
# File 'lib/applitools/selenium/selenium_eyes.rb', line 370

def add_mouse_trigger_by_region_and_location(mouse_action, control, cursor)
  unless last_screenshot
    logger.info "Ignoring #{mouse_action} (no screenshot)"
    return
  end

  Applitools::ArgumentGuard.is_a? control, 'control', Applitools::Region
  Applitools::ArgumentGuard.is_a? cursor, 'cursor', Applitools::Location

  if driver.frame_chain.same_frame_chain? last_screenshot.frame_chain
    logger.info "Ignoring #{mouse_action} (different_frame)"
    return
  end

  add_mouse_trigger_base(mouse_action, control, cursor)
end

#add_text_trigger(control, text) ⇒ Object



318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# File 'lib/applitools/selenium/selenium_eyes.rb', line 318

def add_text_trigger(control, text)
  if disabled?
    logger.info "Ignoring #{text} (disabled)"
    return
  end

  Applitools::ArgumentGuard.not_nil control, 'control'
  return _add_text_trigger(control, text) if control.is_a? Applitools::Region

  pl = control.location
  ds = control.size

  element_region = Applitools::Region.new(pl.x, pl.y, ds.width, ds.height)

  return _add_text_trigger(element_region, text) if control.is_a? Applitools::Selenium::Element
end

#check(*args) ⇒ Applitools::MatchResult

Takes a snapshot and matches it with the expected output.

Parameters:

Returns:

  • (Applitools::MatchResult)

    The match results.



190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'lib/applitools/selenium/selenium_eyes.rb', line 190

def check(*args)
  args.compact!
  case (first_arg = args.shift)
  when String
    name = first_arg
    target = args.shift
  when Applitools::Selenium::Target
    target = first_arg
  when Hash
    target = first_arg[:target]
    name = first_arg[:name] || first_arg[:tag]
  end

  logger.debug "check(#{name}) is called"
  self.tag_for_debug = name
  Applitools::ArgumentGuard.is_a? target, 'target', Applitools::Selenium::Target

  universal_check(name, target)
end

#close_asyncObject



233
234
235
# File 'lib/applitools/selenium/selenium_eyes.rb', line 233

def close_async
  close(false)
end

#configure {|config| ... } ⇒ Object

Yields:



126
127
128
129
# File 'lib/applitools/selenium/selenium_eyes.rb', line 126

def configure
  return unless block_given?
  yield(config)
end

#ensure_configObject



122
123
124
# File 'lib/applitools/selenium/selenium_eyes.rb', line 122

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

#open(options = {}) ⇒ Selenium::WebDriver::Driver

Starts a test

Parameters:

  • options (Hash) (defaults to: {})

    options

Options Hash (options):

  • :driver (Object)

    The driver that controls the browser hosting the application under the test. (Required option)

  • :app_name (String)

    The name of the application under the test. (Required option)

  • :test_name (String)

    The test name (Required option)

  • :viewport_size (String | Hash)

    The required browser’s viewport size (i.e., the visible part of the document’s body) or nil to use the current window’s viewport.

  • :session_type (Object)

    The type of the test (e.g., standard test / visual performance test). Default value is ‘SEQUENTAL’

Returns:

  • (Selenium::WebDriver::Driver)

    The original driver without wrapping



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

def open(options = {})
  # Handle deprecated :browser parameter
  original_driver = get_driver(options)
  options[:driver] = original_driver

  # Real implementation using universal SDK
  universal_open(options)

  # Return the original driver without wrapping it
  original_driver
end