Class | Webrat::Scope |
In: |
lib/webrat/core/scope.rb
|
Parent: | Object |
DATE_TIME_SUFFIXES | = | { :year => '1i', :month => '2i', :day => '3i', :hour => '4i', :minute => '5i' |
session | [R] |
Verifies that an input file field exists on the current page and sets its value to the given file, so that the file will be uploaded along with the form. An optional content_type may be given.
Example:
attach_file "Resume", "/path/to/the/resume.txt" attach_file "Photo", "/path/to/the/image.png", "image/png"
Verifies that an input checkbox exists on the current page and marks it as checked, so that the value will be submitted with the form.
Example:
check 'Remember Me'
Verifies that an input radio button exists on the current page and marks it as checked, so that the value will be submitted with the form.
Example:
choose 'First Option'
Issues a request for the URL pointed to by an area tag on the current page, follows any redirects, and verifies the final page load was successful.
The area used is the first area whose title or id contains the given area_name (case is ignored).
Example:
click_area 'Australia'
Verifies that a submit button exists for the form, then submits the form, follows any redirects, and verifies the final page was successful.
Example:
click_button "Login" click_button
The URL and HTTP method for the form submission are automatically read from the action and method attributes of the <form> element.
Issues a request for the URL pointed to by a link on the current page, follows any redirects, and verifies the final page load was successful.
click_link has very basic support for detecting Rails-generated JavaScript onclick handlers for PUT, POST and DELETE links, as well as CSRF authenticity tokens if they are present.
Javascript imitation can be disabled by passing the option :javascript => false
Passing a :method in the options hash overrides the HTTP method used for making the link request
It will try to find links by (in order of precedence):
innerHTML, with simple handling title id
innerHTML and title are matchable by text subtring or Regexp id is matchable by full text equality or Regexp
Example:
click_link "Sign up" click_link "Sign up", :javascript => false click_link "Sign up", :method => :put
Verifies an input field or textarea exists on the current page, and stores a value for it which will be sent when the form is submitted.
Examples:
fill_in "Email", :with => "user@example.com" fill_in "user[email]", :with => "user@example.com"
The field value is required, and must be specified in options[:with]. field can be either the value of a name attribute (i.e. user[email]) or the text inside a <label> element that points at the <input> field.
Verifies that a an option element exists on the current page with the specified text. You can optionally restrict the search to a specific select list by assigning options[:from] the value of the select list‘s name or a label. Stores the option‘s value to be sent when the form is submitted.
Examples:
select "January" select "February", :from => "event_month" select "February", :from => "Event Month"
Verifies that date elements (year, month, day) exist on the current page with the specified values. You can optionally restrict the search to a specific date‘s elements by assigning options[:from] the value of the date‘s label. Selects all the date elements with date provided. The date provided may be a string or a Date/Time object.
Rail‘s convention is used for detecting the date elements. All elements are assumed to have a shared prefix. You may also specify the prefix by assigning options[:id_prefix].
Examples:
select_date "January 23, 2004" select_date "April 26, 1982", :from => "Birthday" select_date Date.parse("December 25, 2000"), :from => "Event" select_date "April 26, 1982", :id_prefix => 'birthday'
Verifies and selects all the date and time elements on the current page. See select_time and select_date for more details and available options.
Examples:
select_datetime "January 23, 2004 10:30AM" select_datetime "April 26, 1982 7:00PM", :from => "Birthday" select_datetime Time.parse("December 25, 2000 15:30"), :from => "Event" select_datetime "April 26, 1982 5:50PM", :id_prefix => 'birthday'
Verifies that time elements (hour, minute) exist on the current page with the specified values. You can optionally restrict the search to a specific time‘s elements by assigning options[:from] the value of the time‘s label. Selects all the time elements with date provided. The time provided may be a string or a Time object.
Rail‘s convention is used for detecting the time elements. All elements are assumed to have a shared prefix. You may specify the prefix by assigning options[:id_prefix].
Note: Just like Rails’ time_select helper this assumes the form is using 24 hour select boxes, and not 12 hours with AM/PM.
Examples:
select_time "9:30" select_date "3:30PM", :from => "Party Time" select_date Time.parse("10:00PM"), :from => "Event" select_date "10:30AM", :id_prefix => 'meeting'
Verifies that a hidden field exists on the current page and sets the value to that given by the :to option.
Example:
set_hidden_field 'user_id', :to => 1
Submit the form with the given id.
Note that click_button is usually preferrable for simulating form submissions, as you may specify part of the button text rather than the form id.
Example:
submit_form 'login'
Verifies that an input checkbox exists on the current page and marks it as unchecked, so that the value will not be submitted with the form.
Example:
uncheck 'Remember Me'
Verifies that a an option element exists on the current page with the specified text. You can optionally restrict the search to a specific select list by assigning options[:from] the value of the select list‘s name or a label. Remove the option‘s value before the form is submitted.
Examples:
unselect "January" unselect "February", :from => "event_month" unselect "February", :from => "Event Month"