Class: Chop::Form::Field

Inherits:
Struct
  • Object
show all
Defined in:
lib/chop/form.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fieldObject

Returns the value of attribute field

Returns:

  • (Object)

    the current value of field



107
108
109
# File 'lib/chop/form.rb', line 107

def field
  @field
end

#labelObject

Returns the value of attribute label

Returns:

  • (Object)

    the current value of label



107
108
109
# File 'lib/chop/form.rb', line 107

def label
  @label
end

#pathObject

Returns the value of attribute path

Returns:

  • (Object)

    the current value of path



107
108
109
# File 'lib/chop/form.rb', line 107

def path
  @path
end

#sessionObject

Returns the value of attribute session

Returns:

  • (Object)

    the current value of session



107
108
109
# File 'lib/chop/form.rb', line 107

def session
  @session
end

#valueObject

Returns the value of attribute value

Returns:

  • (Object)

    the current value of value



107
108
109
# File 'lib/chop/form.rb', line 107

def value
  @value
end

Class Method Details

.candidatesObject



121
122
123
124
125
# File 'lib/chop/form.rb', line 121

def self.candidates
  descendants.sort_by do |a|
    a == Chop::Form::Default ? 1 : -1 # ensure Default comes last
  end
end

.combined_css_selectorObject



131
132
133
# File 'lib/chop/form.rb', line 131

def self.combined_css_selector
  candidates.map(&:css_selector).uniq.join(", ")
end

.css_selectorObject



127
128
129
# File 'lib/chop/form.rb', line 127

def self.css_selector
  "input"
end

.for(session, label, value, path) ⇒ Object



108
109
110
111
112
113
# File 'lib/chop/form.rb', line 108

def self.for session, label, value, path
  field = FieldFinder.new(session, combined_css_selector).find(label)
  candidates.map do |klass|
    klass.new(session, label, value, path, field)
  end.find(&:matches?)
end

.from(session, field) ⇒ Object



115
116
117
118
119
# File 'lib/chop/form.rb', line 115

def self.from session, field
  candidates.map do |klass|
    klass.new(session, nil, nil, nil, field)
  end.find(&:matches?)
end

Instance Method Details

#diff_valueObject



156
157
158
# File 'lib/chop/form.rb', line 156

def diff_value
  get_value.to_s
end

#fill_in!Object



160
161
162
# File 'lib/chop/form.rb', line 160

def fill_in!
  field.set value
end

#get_valueObject



135
136
137
# File 'lib/chop/form.rb', line 135

def get_value
  field.value
end

#label_textObject



145
146
147
148
149
# File 'lib/chop/form.rb', line 145

def label_text
  return nil unless field[:id].present?
  label_element = session.first("label[for='#{field[:id]}']", visible: :all, minimum: 0, wait: 0.1)
  label_element&.text(:all)
end

#should_include_in_diff?Boolean

Returns:

  • (Boolean)


139
140
141
142
143
# File 'lib/chop/form.rb', line 139

def should_include_in_diff?
  field[:name].present? &&
    field[:type] != "submit" &&
    field[:type] != "hidden"
end

#to_diff_rowObject



151
152
153
154
# File 'lib/chop/form.rb', line 151

def to_diff_row
  return nil unless label = label_text
  [label, diff_value]
end