Class: Applitools::Selenium::EyesTargetLocator

Inherits:
SimpleDelegator
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/applitools/selenium/eyes_target_locator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(driver, original_target_locator, on_will_switch) ⇒ EyesTargetLocator

Initialize a class instance.

Parameters:



14
15
16
17
18
19
# File 'lib/applitools/selenium/eyes_target_locator.rb', line 14

def initialize(driver, original_target_locator, on_will_switch)
  super(original_target_locator)
  @driver = driver
  @on_will_switch = on_will_switch
  @scroll_position_provider = Applitools::Selenium::ScrollPositionProvider.new(driver)
end

Instance Attribute Details

#driverObject (readonly)

Returns the value of attribute driver.



7
8
9
# File 'lib/applitools/selenium/eyes_target_locator.rb', line 7

def driver
  @driver
end

#on_will_switchObject (readonly)

Returns the value of attribute on_will_switch.



7
8
9
# File 'lib/applitools/selenium/eyes_target_locator.rb', line 7

def on_will_switch
  @on_will_switch
end

#scroll_position_providerObject (readonly)

Returns the value of attribute scroll_position_provider.



7
8
9
# File 'lib/applitools/selenium/eyes_target_locator.rb', line 7

def scroll_position_provider
  @scroll_position_provider
end

Instance Method Details

#active_elementApplitools::Selenium::Element

A wrapper for the native method active_element.

Returns:



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
# File 'lib/applitools/selenium/eyes_target_locator.rb', line 100

def active_element
  logger.info 'EyesTargetLocator.active_element()'
  logger.info 'Switching to element...'
  element = __getobj__.active_element

  unless element.is_a? Selenium::WebDriver::Element
    raise Applitools::EyesError.new(
      'Not an Selenium::WebDriver::Element!'
    )
  end

  result = Applitools::Selenium::Element.new driver, element

  logger.info 'Done!'
  result
end

#alertApplitools::Selenium::EyesTargetLocator

A wrapper for a native method alert.

Returns:



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

def alert
  logger.info 'EyesTargetLocator.alert()'
  logger.info 'Switching to alert...'
  result = __getobj__.alert
  logger.info 'Done!'
  result
end

#default_contentApplitools::Selenium::Driver

A wrapper for the native method default_content.

Returns:



72
73
74
75
76
77
78
79
80
81
82
# File 'lib/applitools/selenium/eyes_target_locator.rb', line 72

def default_content
  logger.info 'EyesTargetLocator.default_content()'
  unless driver.frame_chain.empty?
    logger.info 'Making preparations...'
    on_will_switch.will_switch_to_frame :default_content, nil
    logger.info 'Done! Switching to default content...'
    __getobj__.default_content
    logger.info 'Done!'
  end
  driver
end

#frame(options = {}) ⇒ Object

Set a certain iframe.

Parameters:

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

    The possible options.

Options Hash (options):

  • :index (Fixnum)

    The index of the frame.

  • :name_or_id (String)

    The name of the frame.

  • :frameElement (WebElement)

    The element with the frame.



27
28
29
30
31
32
33
34
35
36
# File 'lib/applitools/selenium/eyes_target_locator.rb', line 27

def frame(options = {})
  raise Applitools::EyesIllegalArgument.new 'You must pass :index or :name_or_id or :frame_element option' unless
      options[:index] || options[:name_or_id] || options[:frame_element]
  if (needed_keys = (options.keys & [:index, :name_or_id, :frame_element])).length == 1
    send "frame_by_#{needed_keys.first}", options[needed_keys.first]
  else
    raise Applitools::EyesIllegalArgument.new 'You\'ve passed some extra keys!' /
      'Only :index, :name_or_id or :frame_elenent are allowed.'
  end
end

#frames(options = {}) ⇒ Object

Sets several frames.

Parameters:

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

    The options for the frames.

Options Hash (options):

  • :frame_chain (Applitools::Selenium::FrameChain)

    The frame chain.

  • :frames_path (String)

    The frames paths.



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/applitools/selenium/eyes_target_locator.rb', line 57

def frames(options = {})
  raise Applitools::EyesIllegalArgument.new 'You must pass :frame_chain or :frames_path' if
      options[:frame_chain].nil? & options[:frames_path].nil?

  if (needed_keys = (options.keys & [:frame_chain, :frames_path])).length == 1
    send "frames_by_#{needed_keys.first}", options[needed_keys.first]
  else
    raise Applitools::EyesIllegalArgument.new 'You\'ve passed some extra keys!' /
      'Only :frame_index or :frames_path are allowed.'
  end
end

#parent_frameApplitools::Selenium::Driver

Switches to parent frame.

Returns:



41
42
43
44
45
46
47
48
49
50
# File 'lib/applitools/selenium/eyes_target_locator.rb', line 41

def parent_frame
  logger.info 'EyesTargetLocator.parent_frame()'
  unless driver.frame_chain.empty?
    on_will_switch.will_switch_to_frame :parent_frame, nil
    logger.info 'Done! Switching to parent_frame...'
    __getobj__.parent_frame
  end
  logger.info 'Done!'
  driver
end

#window(name_or_handle) ⇒ Applitools::Selenium::Driver

A wrapper for the native method window.

Returns:



87
88
89
90
91
92
93
94
95
# File 'lib/applitools/selenium/eyes_target_locator.rb', line 87

def window(name_or_handle)
  logger.info 'EyesTargetLocator.window()'
  logger.info 'Making preparaions...'
  on_will_switch.will_switch_to_window name_or_handle
  logger.info 'Done! Switching to window..'
  __getobj__.window name_or_handle
  logger.info 'Done!'
  driver
end