Class: CapybaraPageObject::Form

Inherits:
Element show all
Defined in:
lib/capybara-page-object/elements/form.rb

Instance Attribute Summary

Attributes inherited from Node

#source

Instance Method Summary collapse

Methods included from HTML5Data

#data

Methods included from Collections

#key, #value

Methods inherited from Node

#classes, element, field, from_string, #initialize

Methods included from Delegators

#all, #find, #text

Constructor Details

This class inherits a constructor from CapybaraPageObject::Node

Instance Method Details

#buttonsObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/capybara-page-object/elements/form.rb', line 13

def buttons
  r = []
  all('input').each do |element|
    input = Input.new(element)
    next unless input.button?
    r << element
  end
  all('button').each do |button|
    r << button
  end
  r
end

#fieldsObject



6
7
8
9
10
11
# File 'lib/capybara-page-object/elements/form.rb', line 6

def fields
  r = ActiveSupport::OrderedHash.new
  r.merge! inputs
  r.merge! selects
  r.merge! textareas
end

#inputsObject



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/capybara-page-object/elements/form.rb', line 26

def inputs
  all('input').each_with_object(ActiveSupport::OrderedHash.new) do |input_tag, hash|
    input = Input.new(input_tag)
    next if input.button?
    if input.checkable?
      hash[input.key] = !! input.checked?
    else
      hash[input.key] = input_tag.value
    end
  end
end

#selectsObject



45
46
47
48
49
50
# File 'lib/capybara-page-object/elements/form.rb', line 45

def selects
  all('select').inject(ActiveSupport::OrderedHash.new) do |result, element|
    select = Select.new(element)
    result.merge select.key => select.value
  end
end

#textareasObject



38
39
40
41
42
43
# File 'lib/capybara-page-object/elements/form.rb', line 38

def textareas
  all('textarea').inject(ActiveSupport::OrderedHash.new) do |result, element|
    textarea = Textarea.new(element)
    result.merge textarea.key => textarea.value
  end
end