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



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

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_elementObject

A wrapper for the native method active_element



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

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

#alertObject

A wrapper for a native method alert



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

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

#default_contentObject

A wrapper for the native method default_content



60
61
62
63
64
65
66
67
68
69
70
# File 'lib/applitools/selenium/eyes_target_locator.rb', line 60

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 = {}) ⇒ Applitools::Selenium::Driver

Options Hash (options):

  • :index (Fixnum)
  • :name_or_id (String)
  • :frameElement (WebElement)


21
22
23
24
25
26
27
28
29
30
# File 'lib/applitools/selenium/eyes_target_locator.rb', line 21

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

Returns Applitools::Selenium::Driver.

Options Hash (options):

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


47
48
49
50
51
52
53
54
55
56
57
# File 'lib/applitools/selenium/eyes_target_locator.rb', line 47

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_frameObject



32
33
34
35
36
37
38
39
40
41
# File 'lib/applitools/selenium/eyes_target_locator.rb', line 32

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) ⇒ Object

A wrapper for the native method window



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

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