Class: AePageObjects::ElementProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/ae_page_objects/element_proxy.rb

Instance Method Summary collapse

Constructor Details

#initialize(element_class, *args, &block) ⇒ ElementProxy

Returns a new instance of ElementProxy.



12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/ae_page_objects/element_proxy.rb', line 12

def initialize(element_class, *args, &block)
  @element_class = element_class
  @args          = args
  @block         = block
  
  # Yield to the block immediately by creating 
  # the element. Block use assumes presence. Since
  # the underlying element is passed when yielding
  # the block level variable won't have access to
  # the proxy methods, but that's ok.
  if block_given?
    element
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args, &block) ⇒ Object



72
73
74
75
76
77
78
# File 'lib/ae_page_objects/element_proxy.rb', line 72

def method_missing(name, *args, &block)
  if name == "class"
    return @element_class
  end
  
  element.__send__(name, *args, &block)
end

Instance Method Details

#is_a?(type) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/ae_page_objects/element_proxy.rb', line 64

def is_a?(type)
  type == @element_class || type == ElementProxy
end

#kind_of?(type) ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/ae_page_objects/element_proxy.rb', line 68

def kind_of?(type)
  is_a?(type)
end

#not_present?Boolean

Returns:

  • (Boolean)


48
49
50
51
52
53
54
55
56
# File 'lib/ae_page_objects/element_proxy.rb', line 48

def not_present?
  Capybara.current_session.wait_until do
    Capybara.using_wait_time(0) do
      ! present?
    end
  end
rescue Capybara::TimeoutError
  false
end

#not_visible?Boolean

Returns:

  • (Boolean)


34
35
36
37
38
39
40
41
42
# File 'lib/ae_page_objects/element_proxy.rb', line 34

def not_visible?
  Capybara.current_session.wait_until do
    Capybara.using_wait_time(0) do
      ! visible?
    end
  end
rescue Capybara::TimeoutError
  false  
end

#presenceObject



58
59
60
61
62
# File 'lib/ae_page_objects/element_proxy.rb', line 58

def presence
  element
rescue Capybara::ElementNotFound
  nil
end

#present?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/ae_page_objects/element_proxy.rb', line 44

def present?
  ! presence.nil?
end

#respond_to?(*args) ⇒ Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/ae_page_objects/element_proxy.rb', line 80

def respond_to?(*args)
  super || @element_class.allocate.respond_to?(*args)
end

#visible?Boolean

Provided so that visible? can be asked without an explicit check for present? first.

Returns:

  • (Boolean)


29
30
31
32
# File 'lib/ae_page_objects/element_proxy.rb', line 29

def visible?
  inst = presence
  ! inst.nil? && inst.visible?
end