lib/mechanical-cuke.rb in mechanical-cuke-0.2.0 vs lib/mechanical-cuke.rb in mechanical-cuke-0.3.0
- old
+ new
@@ -6,23 +6,32 @@
class << self
attr_accessor :save_and_open_page_path
def configure
yield self
end
-# TODO: try def get blah blah
end
-end
-World do
- session = Mechanize.new
-end
+ def mechanize
+ @mechanize ||= Mechanize.new
+ end
-private
+ def get(url)
+ mechanize.get(url)
+ end
-def response_body
- current_page.body
+ def current_page
+ mechanize.current_page
+ end
+
+ def response_body
+ current_page.body
+ end
end
+
+World(MechanicalCuke)
+
+private
def form
current_page.forms.first
end
@@ -62,9 +71,28 @@
end
# And by label
if (node = find_by_label(field))
return form.radiobutton_with(:node => node)
+ end
+
+ return nil
+end
+
+def find_checkbox(field)
+ # Search by id
+ if (node = find_by_id(field))
+ return form.checkbox_with(:node => node.first)
+ end
+
+ # Then by name
+ if (f = form.checkbox_with(:name => field))
+ return f
+ end
+
+ # And finally by label
+ if (node = find_by_label(field))
+ return form.checkbox_with(:node => node)
end
return nil
end