module Pouch::Elements

Public Instance Methods

button(name, identifier, *args, &block) click to toggle source
# File lib/pouch/elements.rb, line 14
def button name, identifier, *args, &block
  element :button, name, identifier, args, &block
end
checkbox(name, identifier, *args, &block) click to toggle source
# File lib/pouch/elements.rb, line 18
def checkbox name, identifier, *args, &block
  identifier.merge! type: 'checkbox'
  element :input, name, identifier, args, &block
end
div(name, identifier, *args, &block) click to toggle source
# File lib/pouch/elements.rb, line 23
def div name, identifier, *args, &block
  element :div, name, identifier, args, &block
end
element(tag, name, identifier, *args, &block) click to toggle source
# File lib/pouch/elements.rb, line 4
def element tag, name, identifier, *args, &block
  define_method name, ->(time = nil) do
    timer(time){ browser.element(tag, identifier).visible? }
    return browser.element tag, identifier unless block_given?
    block.call browser.send(:element, tag, identifier), *args        
  end

  define_waiting_methods tag, name, identifier, *args, &block
end
file_field(name, identifier, *args, &block) click to toggle source
# File lib/pouch/elements.rb, line 27
def file_field name, identifier, *args, &block
  identifier.merge! type: 'file'
  element :input, name, identifier, args, &block
end
form(name, identifier, *args, &block) click to toggle source
# File lib/pouch/elements.rb, line 32
def form name, identifier, *args, &block
  element :form, name, identifier, args, &block
end
h1(name, identifier, *args, &block) click to toggle source
# File lib/pouch/elements.rb, line 36
def h1 name, identifier, *args, &block
  element :h1, name, identifier, args, &block
end
h2(name, identifier, *args, &block) click to toggle source
# File lib/pouch/elements.rb, line 40
def h2 name, identifier, *args, &block
  element :h2, name, identifier, args, &block
end
h3(name, identifier, *args, &block) click to toggle source
# File lib/pouch/elements.rb, line 44
def h3 name, identifier, *args, &block
  element :h3, name, identifier, args, &block
end
h4(name, identifier, *args, &block) click to toggle source
# File lib/pouch/elements.rb, line 48
def h4 name, identifier, *args, &block
  element :h4, name, identifier, args, &block
end
h5(name, identifier, *args, &block) click to toggle source
# File lib/pouch/elements.rb, line 52
def h5 name, identifier, *args, &block
  element :h5, name, identifier, args, &block
end
h6(name, identifier, *args, &block) click to toggle source
# File lib/pouch/elements.rb, line 56
def h6 name, identifier, *args, &block
  element :h6, name, identifier, args, &block
end
image(name, identifier, *args, &block) click to toggle source
# File lib/pouch/elements.rb, line 60
def image name, identifier, *args, &block
  element :img, name, identifier, args, &block
end
list_item(name, identifier, *args, &block) click to toggle source
# File lib/pouch/elements.rb, line 68
def list_item name, identifier, *args, &block
  element :li, name, identifier, args, &block
end
ordered_list(name, identifier, *args, &block) click to toggle source
# File lib/pouch/elements.rb, line 72
def ordered_list name, identifier, *args, &block
  element :ol, name, identifier, args, &block
end
paragraph(name, identifier, *args, &block) click to toggle source
# File lib/pouch/elements.rb, line 76
def paragraph name, identifier, *args, &block
  element :p, name, identifier, args, &block
end
radio_button(name, identifier, *args, &block) click to toggle source
# File lib/pouch/elements.rb, line 80
def radio_button name, identifier, *args, &block
  identifier.merge! type: 'radio'
  element :input, name, identifier, args, &block
end
select_list(name, identifier, *args, &block) click to toggle source
# File lib/pouch/elements.rb, line 85
def select_list name, identifier, *args, &block
  element :select, name, identifier, args, &block
end
span(name, identifier, *args, &block) click to toggle source
# File lib/pouch/elements.rb, line 89
def span name, identifier, *args, &block
  element :span, name, identifier, args, &block
end
table(name, identifier, *args, &block) click to toggle source
# File lib/pouch/elements.rb, line 93
def table name, identifier, *args, &block
  element :table, name, identifier, args, &block
end
table_cell(name, identifier, *args, &block) click to toggle source
# File lib/pouch/elements.rb, line 97
def table_cell name, identifier, *args, &block
  element :td, name, identifier, args, &block
end
table_header(name, identifier, *args, &block) click to toggle source
# File lib/pouch/elements.rb, line 101
def table_header name, identifier, *args, &block
  element :th, name, identifier, args, &block
end
table_row(name, identifier, *args, &block) click to toggle source
# File lib/pouch/elements.rb, line 105
def table_row name, identifier, *args, &block
  element :tr, name, identifier, args, &block
end
text_area(name, identifier, *args, &block) click to toggle source
# File lib/pouch/elements.rb, line 109
def text_area name, identifier, *args, &block
  element :textarea, name, identifier, args, &block
end
text_field(name, identifier, *args, &block) click to toggle source
# File lib/pouch/elements.rb, line 113
def text_field name, identifier, *args, &block
  element :input, name, identifier, args, &block
end
unordered_list(name, identifier, *args, &block) click to toggle source
# File lib/pouch/elements.rb, line 117
def unordered_list name, identifier, *args, &block
  element :ul, name, identifier, args, &block
end

Private Instance Methods

define_waiting_methods(tag, name, identifier, *args, &block) click to toggle source
# File lib/pouch/elements.rb, line 123
def define_waiting_methods tag, name, identifier, *args, &block
  define_method "when_#{name}_not_visible", ->(time = nil) do
    result = negative_timer(time){ !browser.element(tag, identifier).visible? }
    unless result
      raise VisibilityError, "#{name} element is still visible"
    end
    self
  end
  
  define_method "when_#{name}_present", ->(time = nil) do
    timer(time){ browser.element(tag, identifier).present? }
    html_element = browser.element tag, identifier
    return located_element unless block_given?
    block.call located_element, *args
  end

  define_method "when_#{name}_not_present", ->(time = nil) do
    result = negative_timer(time){ !browser.element(tag, identifier).present? }
    unless result
      raise PresenceError, "#{name} element is still present"
    end
    self
  end
end
negative_timer(n) { |block rescue false| ... } click to toggle source
# File lib/pouch/elements.rb, line 157
def negative_timer n, &block
  interval = n.nil? ? timeout : n
  timed_out = Time.now + interval
  until Time.now > timed_out
    result = yield block rescue false
    return result if result
  end
  false
end
timer(n) { |block rescue false| ... } click to toggle source
# File lib/pouch/elements.rb, line 148
def timer n, &block
  interval = n.nil? ? timeout : n
  timed_out = Time.now + timeout
  until Time.now > timed_out
    result = yield block rescue false
    break if result
  end
end