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:



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

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.



9
10
11
# File 'lib/applitools/selenium/eyes_target_locator.rb', line 9

def driver
  @driver
end

#on_will_switchObject (readonly)

Returns the value of attribute on_will_switch.



9
10
11
# File 'lib/applitools/selenium/eyes_target_locator.rb', line 9

def on_will_switch
  @on_will_switch
end

#scroll_position_providerObject (readonly)

Returns the value of attribute scroll_position_provider.



9
10
11
# File 'lib/applitools/selenium/eyes_target_locator.rb', line 9

def scroll_position_provider
  @scroll_position_provider
end

Instance Method Details

#active_elementApplitools::Selenium::Element

A wrapper for the native method active_element.

Returns:



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/applitools/selenium/eyes_target_locator.rb', line 112

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:



132
133
134
135
136
137
138
# File 'lib/applitools/selenium/eyes_target_locator.rb', line 132

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:



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

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(*args) ⇒ Object

Set a certain iframe.

Parameters:

  • options (Hash)

    The possible options.



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/applitools/selenium/eyes_target_locator.rb', line 29

def frame(*args)
  case value = args[0]
  when Hash
    options = value
    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
  when Applitools::Selenium::Element
    frame_by_frame_element(value)
  when String
    frame_by_name_or_id(value)
  else
    raise Applitools::EyesError, 'Unknown frame selector to switch!'
  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.



69
70
71
72
73
74
75
76
77
78
79
# File 'lib/applitools/selenium/eyes_target_locator.rb', line 69

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:



53
54
55
56
57
58
59
60
61
62
# File 'lib/applitools/selenium/eyes_target_locator.rb', line 53

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:



99
100
101
102
103
104
105
106
107
# File 'lib/applitools/selenium/eyes_target_locator.rb', line 99

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