Class: Applitools::Selenium::Configuration

Inherits:
EyesBaseConfiguration
  • Object
show all
Defined in:
lib/applitools/selenium/configuration.rb

Constant Summary collapse

DEFAULT_CONFIG =
proc do
  {
    # force_full_page_screenshot: false,
    wait_before_screenshots: 0.1,
    # stitch_mode: Applitools::Selenium::StitchModes::CSS,
    hide_scrollbars: true,
    hide_caret: false,
    browsers_info: Applitools::Selenium::BrowsersInfo.new,
    rendering_grid_force_put: (ENV['APPLITOOLS_RENDERING_GRID_FORCE_PUT'] || 'false').casecmp('true') == 0,
    visual_grid_options: {}
  }
end

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.default_configObject



24
25
26
# File 'lib/applitools/selenium/configuration.rb', line 24

def default_config
  super.merge DEFAULT_CONFIG.call
end

Instance Method Details

#add_browserConfiguration #add_browser(browser_info) ⇒ Configuration #add_browser(width, height, browser_type) ⇒ Configuration

Adds a browser configuration to be used for visual grid testing.

This method can be called in several ways:

  1. No arguments: Creates a default desktop browser configuration

  2. One argument: Must be an IRenderBrowserInfo instance (like DesktopBrowserInfo or IosDeviceInfo)

  3. Three arguments: width, height, and browser type to create a desktop browser config

  4. With a block: Allows further configuration of the browser using fluent interface

Examples:

Add a default browser

config.add_browser

Add a specific browser with viewport size

config.add_browser(1200, 800, :chrome)

Add a browser with fluent interface

config.add_browser do |browser|
  browser.viewport_size(1200, 800)
        .browser_type(:chrome)
end

Add a pre-configured browser info

desktop_browser = Applitools::Selenium::DesktopBrowserInfo.new
desktop_browser.viewport_size = Applitools::RectangleSize.new(1200, 800)
desktop_browser.browser_type = :chrome
config.add_browser(desktop_browser)

Overloads:

  • #add_browserConfiguration

    Creates a default desktop browser configuration

  • #add_browser(browser_info) ⇒ Configuration

    Parameters:

    Raises:

    • (Applitools::EyesIllegalArgument)

      if browser_info is not an IRenderBrowserInfo instance

  • #add_browser(width, height, browser_type) ⇒ Configuration

    Parameters:

    • width (Integer)

      The viewport width

    • height (Integer)

      The viewport height

    • browser_type (Symbol)

      The browser type (e.g., :chrome, :firefox)

Yields:

  • (browser_config)

    Yields a RenderBrowserInfoFluent for further configuration

Yield Parameters:

Returns:



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# File 'lib/applitools/selenium/configuration.rb', line 148

def add_browser(*args)
  case args.size
  when 0
    browser = Applitools::Selenium::DesktopBrowserInfo.new
  when 1
    b = args[0]
    raise(
      Applitools::EyesIllegalArgument,
      'Expected :browser to be an IRenderBrowserInfo instance!'
    ) unless b.is_a? IRenderBrowserInfo
    browser = b
  when 3
    browser = Applitools::Selenium::DesktopBrowserInfo.new.tap do |bi|
      bi.viewport_size = Applitools::RectangleSize.new(args[0], args[1])
      bi.browser_type = args[2]
    end
  end
  yield(Applitools::Selenium::RenderBrowserInfoFluent.new(browser)) if block_given?
  browsers_info.add browser
  # self.viewport_size = browser.viewport_size unless viewport_size
  self
end

#add_browsers(*browsers) ⇒ Configuration

Adds multiple browser configurations to be used for visual grid testing.

This method takes an array of browser configurations and adds them all to the current Eyes configuration. It’s useful for configuring multiple browsers at once, such as when testing across different browsers and devices.

Examples:

Add multiple browser configurations

config.add_browsers(
  desktop_browser_info,
  ios_device_info,
  chrome_emulation_info
)

Add an array of browser configurations

browsers = [desktop_browser_info, ios_device_info]
config.add_browsers(browsers)

Parameters:

Returns:



192
193
194
195
196
197
198
199
200
201
202
203
# File 'lib/applitools/selenium/configuration.rb', line 192

def add_browsers(*browsers)
  browsers = case browsers.first
               when Applitools::Selenium::IRenderBrowserInfo
                 browsers
               when Array
                 browsers.first
             end
  browsers.each do |browser|
    add_browser(browser)
  end
  self
end

#add_device_emulation(device_name, orientation = Orientations::PORTRAIT) ⇒ Configuration

Adds a Chrome device emulation configuration for visual grid testing.

This method configures the visual grid to render using Chrome’s device emulation mode, which simulates various mobile devices in desktop Chrome. This is useful for testing responsive designs across different device profiles.

Examples:

Add iPhone X emulation

config.add_device_emulation(Devices::iPhone_X)

Add iPad emulation in landscape mode

config.add_device_emulation(Devices::iPad, Orientations::LANDSCAPE)

Parameters:

  • device_name (Symbol)

    The device to emulate, must be one of the values in Devices.enum_values

  • orientation (Symbol) (defaults to: Orientations::PORTRAIT)

    The screen orientation, defaults to portrait

Returns:

Raises:

  • (Applitools::EyesIllegalArgument)

    if device_name is not in the list of supported devices



222
223
224
225
226
227
# File 'lib/applitools/selenium/configuration.rb', line 222

def add_device_emulation(device_name, orientation = Orientations::PORTRAIT)
  Applitools::ArgumentGuard.not_nil device_name, 'device_name'
  raise Applitools::EyesIllegalArgument, 'Wrong device name!' unless Devices.enum_values.include? device_name
  emu = Applitools::Selenium::ChromeEmulationInfo.new(device_name, orientation)
  add_browser emu
end

#add_mobile_device(mobile_device_info) ⇒ Configuration

Adds a single mobile device configuration for visual grid testing.

This is a convenience method that delegates to add_mobile_devices.

Parameters:

Returns:

See Also:



236
237
238
# File 'lib/applitools/selenium/configuration.rb', line 236

def add_mobile_device(mobile_device_info)
  add_mobile_devices(mobile_device_info)
end

#add_mobile_devices(mobile_device_infos) ⇒ Configuration

Adds multiple mobile device configurations for visual grid testing.

This method is a semantic alias for add_browsers that makes code more readable when specifically adding mobile device configurations.

Parameters:

  • mobile_device_infos (Array<IRenderBrowserInfo>)

    An array of mobile device configurations

Returns:

See Also:



248
249
250
# File 'lib/applitools/selenium/configuration.rb', line 248

def add_mobile_devices(mobile_device_infos)
  add_browsers(mobile_device_infos)
end

#add_multi_device_target(*args) ⇒ Configuration

Adds multiple mobile device targets to the configuration.

This method supports several ways to specify device information:

  • A hash with device configuration (e.g., { device_name: ‘iPhone 13’, screen_orientation: ‘portrait’ })

  • A single device name as a string or symbol (e.g., ‘iPhone 13’ or :iPhone_13)

  • Multiple device names as separate arguments

  • A platform flag to explicitly specify Android or iOS (e.g., { device_name: ‘Pixel 5’, platform: :android })

Device names must be one of the valid device names from the respective platform:

  • iOS device names from IosMultiDeviceTargetGenerated (‘iPhone 13’, ‘iPhone 14 Pro’, etc.)

  • Android device names from AndroidMultiDeviceTargetGenerated (‘Pixel 5’, ‘Galaxy S22’, etc.)

If no platform is specified, the method will attempt to determine the platform based on the device name.

Examples:

Add a single iOS device using a hash

config.add_multi_device_target(device_name: 'iPhone 13', screen_orientation: 'portrait')

Add a single Android device using a hash

config.add_multi_device_target(device_name: 'Pixel 5', platform: :android, screen_orientation: 'portrait')

Add a single device using a string (platform detected automatically)

config.add_multi_device_target('iPhone 13')  # iOS detected
config.add_multi_device_target('Pixel 5')    # Android detected

Add multiple devices

config.add_multi_device_target('iPhone 13', 'Pixel 5', 'Galaxy S22')

Parameters:

  • args (Array)

    device names or configuration hashes

Options Hash (*args):

  • :device_name (String, Symbol)

    The name of the mobile device

  • :screen_orientation (String, Symbol)

    The screen orientation (‘portrait’ or ‘landscape’)

  • :ios_version (String)

    The iOS version to use (for iOS devices)

  • :android_version (String)

    The Android version to use (for Android devices)

  • :platform (Symbol)

    The platform (:ios or :android)

Returns:



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/applitools/selenium/configuration.rb', line 82

def add_multi_device_target(*args)
  mobile_devices = []

  if args.length == 1 && args[0].is_a?(Hash)
    # Single hash passed directly
    mobile_devices << create_mobile_device_info(args[0])
  elsif args.any? { |arg| arg.is_a?(Hash) }
    # One of the arguments is a hash with device configuration
    hash_arg = args.find { |arg| arg.is_a?(Hash) }
    mobile_devices << create_mobile_device_info(hash_arg)
  else
    # Multiple device names as symbols or strings
    args.each do |device_name|
      mobile_devices << create_mobile_device_info(device_name: device_name)
    end
  end

  # Add each mobile device to the configuration
  add_browsers(*mobile_devices)
  # Return the configuration object for method chaining
  self
end

#custom_setter_for_visual_grid_options(value) ⇒ Object



42
43
44
45
# File 'lib/applitools/selenium/configuration.rb', line 42

def custom_setter_for_visual_grid_options(value)
  return {} if value.nil?
  value
end

#viewport_sizeObject

Move viewport_size above the private methods



253
254
255
256
257
258
259
260
# File 'lib/applitools/selenium/configuration.rb', line 253

def viewport_size
  user_defined_vp = super
  user_defined_vp = nil if user_defined_vp.respond_to?(:square) && user_defined_vp.square == 0
  return user_defined_vp if user_defined_vp
  # from_browsers_info = browsers_info.select { |bi| bi.viewport_size.square > 0 }.first
  # return from_browsers_info.viewport_size if from_browsers_info
  nil
end