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



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

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)


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

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

#kind_of?(type) ⇒ Boolean

Returns:

  • (Boolean)


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

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

#not_present?Boolean

Returns:

  • (Boolean)


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

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)


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

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

#presenceObject



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

def presence
  element
rescue Capybara::ElementNotFound
  nil
end

#present?Boolean

Returns:

  • (Boolean)


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

def present?
  presence.present?
end

#respond_to?(*args) ⇒ Boolean

Returns:

  • (Boolean)


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

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
# File 'lib/ae_page_objects/element_proxy.rb', line 29

def visible?
  !!presence.try(:visible?)
end