Parent

Included Modules

Capybara::Session

Constants

DSL_METHODS

Attributes

app[R]
mode[R]

Public Class Methods

new(mode, app=nil) click to toggle source
# File lib/capybara/session.rb, line 20
def initialize(mode, app=nil)
  @mode = mode
  @app = app
end

Public Instance Methods

attach_file(locator, path) click to toggle source
# File lib/capybara/session.rb, line 96
def attach_file(locator, path)
  msg = "cannot attach file, no file field with id, name, or label '#{locator}' found"
  locate(:xpath, XPath.file_field(locator), msg).set(path)
end
check(locator) click to toggle source
# File lib/capybara/session.rb, line 76
def check(locator)
  msg = "cannot check field, no checkbox with id, name, or label '#{locator}' found"
  locate(:xpath, XPath.checkbox(locator), msg).set(true)
end
choose(locator) click to toggle source
# File lib/capybara/session.rb, line 71
def choose(locator)
  msg = "cannot choose field, no radio button with id, name, or label '#{locator}' found"
  locate(:xpath, XPath.radio_button(locator), msg).set(true)
end
click(locator) click to toggle source
# File lib/capybara/session.rb, line 44
def click(locator)
  msg = "no link or button '#{locator}' found"
  locate(:xpath, XPath.link(locator).button(locator), msg).click
end
click_button(locator) click to toggle source
# File lib/capybara/session.rb, line 54
def click_button(locator)
  msg = "no button with value or id or text '#{locator}' found"
  locate(:xpath, XPath.button(locator), msg).click
end
drag(source_locator, target_locator) click to toggle source
# File lib/capybara/session.rb, line 59
def drag(source_locator, target_locator)
  source = locate(:xpath, source_locator, "drag source '#{source_locator}' not found on page")
  target = locate(:xpath, target_locator, "drag target '#{target_locator}' not found on page")
  source.drag_to(target)
end
driver() click to toggle source
# File lib/capybara/session.rb, line 25
def driver
  @driver ||= begin                    
    string = mode.to_s
    string.gsub!(%{(^.)|(_.)}) { |m| m[m.length-1,1].upcase }
    Capybara::Driver.const_get(string.to_sym).new(app)
  rescue NameError
    raise Capybara::DriverNotFoundError, "no driver called #{mode} was found"
  end
end
evaluate_script(script) click to toggle source
# File lib/capybara/session.rb, line 252
def evaluate_script(script)
  driver.evaluate_script(script)
end
execute_script(script) click to toggle source
# File lib/capybara/session.rb, line 248
def execute_script(script)
  driver.execute_script(script)
end
fill_in(locator, options={}) click to toggle source
# File lib/capybara/session.rb, line 65
def fill_in(locator, options={})
  msg = "cannot fill in, no text field, text area or password field with id, name, or label '#{locator}' found"
  raise "Must pass a hash containing 'with'" if not options.is_a?(Hash) or not options.has_key?(:with)
  locate(:xpath, XPath.fillable_field(locator), msg).set(options[:with])
end
has_button?(locator) click to toggle source
# File lib/capybara/session.rb, line 191
def has_button?(locator)
  has_xpath?(XPath.button(locator))
end
has_checked_field?(locator) click to toggle source
# File lib/capybara/session.rb, line 207
def has_checked_field?(locator)
  has_xpath?(XPath.field(locator, :checked => true))
end
has_content?(content) click to toggle source
# File lib/capybara/session.rb, line 175
def has_content?(content)
  has_xpath?(XPath.content(content))
end
has_css?(path, options={}) click to toggle source
# File lib/capybara/session.rb, line 167
def has_css?(path, options={})
  has_xpath?(XPath.from_css(path), options)
end
has_field?(locator, options={}) click to toggle source
# File lib/capybara/session.rb, line 199
def has_field?(locator, options={})
  has_xpath?(XPath.field(locator, options))
end
has_no_button?(locator) click to toggle source
# File lib/capybara/session.rb, line 195
def has_no_button?(locator)
  has_no_xpath?(XPath.button(locator))
end
has_no_content?(content) click to toggle source
# File lib/capybara/session.rb, line 179
def has_no_content?(content)
  has_no_xpath?(XPath.content(content))
end
has_no_css?(path, options={}) click to toggle source
# File lib/capybara/session.rb, line 171
def has_no_css?(path, options={})
  has_no_xpath?(XPath.from_css(path), options)
end
has_no_field?(locator, options={}) click to toggle source
# File lib/capybara/session.rb, line 203
def has_no_field?(locator, options={})
  has_no_xpath?(XPath.field(locator, options))
end
has_no_select?(locator, options={}) click to toggle source
# File lib/capybara/session.rb, line 219
def has_no_select?(locator, options={})
  has_no_xpath?(XPath.select(locator, options))
end
has_no_table?(locator, options={}) click to toggle source
# File lib/capybara/session.rb, line 227
def has_no_table?(locator, options={})
  has_no_xpath?(XPath.table(locator, options))
end
has_no_xpath?(path, options={}) click to toggle source
# File lib/capybara/session.rb, line 153
def has_no_xpath?(path, options={})
  wait_conditionally_until do
    results = all(:xpath, path, options)

    if options[:count]
      results.size != options[:count]
    else
      results.empty?
    end
  end
rescue Capybara::TimeoutError
  return false
end
has_select?(locator, options={}) click to toggle source
# File lib/capybara/session.rb, line 215
def has_select?(locator, options={})
  has_xpath?(XPath.select(locator, options))
end
has_table?(locator, options={}) click to toggle source
# File lib/capybara/session.rb, line 223
def has_table?(locator, options={})
  has_xpath?(XPath.table(locator, options))
end
has_unchecked_field?(locator) click to toggle source
# File lib/capybara/session.rb, line 211
def has_unchecked_field?(locator)
  has_xpath?(XPath.field(locator, :unchecked => true))
end
has_xpath?(path, options={}) click to toggle source
# File lib/capybara/session.rb, line 139
def has_xpath?(path, options={})
  wait_conditionally_until do
    results = all(:xpath, path, options)

    if options[:count]
      results.size == options[:count]
    else
      results.size > 0
    end
  end
rescue Capybara::TimeoutError
  return false
end
locate(kind_or_locator, locator=nil, fail_msg = nil) click to toggle source

return node identified by locator or raise ElementNotFound(using desc)

# File lib/capybara/session.rb, line 237
def locate(kind_or_locator, locator=nil, fail_msg = nil)
  node = wait_conditionally_until { find(kind_or_locator, locator) }
ensure
  raise Capybara::ElementNotFound, fail_msg || "Unable to locate '#{locator || kind_or_locator}'" unless node
  return node
end
save_and_open_page() click to toggle source
# File lib/capybara/session.rb, line 231
def save_and_open_page
  require 'capybara/save_and_open_page'
  Capybara::SaveAndOpenPage.save_and_open_page(body)
end
scope_to(*locator) click to toggle source
# File lib/capybara/session.rb, line 131
def scope_to(*locator)
  scoped_session = self.clone
  scoped_session.instance_eval do
    @scopes = scopes + locator
  end
  scoped_session
end
select(value, options={}) click to toggle source
# File lib/capybara/session.rb, line 86
def select(value, options={})
  msg = "cannot select option, no select box with id, name, or label '#{options[:from]}' found"
  locate(:xpath, XPath.select(options[:from]), msg).select(value)
end
uncheck(locator) click to toggle source
# File lib/capybara/session.rb, line 81
def uncheck(locator)
  msg = "cannot uncheck field, no checkbox with id, name, or label '#{locator}' found"
  locate(:xpath, XPath.checkbox(locator), msg).set(false)
end
unselect(value, options={}) click to toggle source
# File lib/capybara/session.rb, line 91
def unselect(value, options={})
  msg = "cannot unselect option, no select box with id, name, or label '#{options[:from]}' found"
  locate(:xpath, XPath.select(options[:from]), msg).unselect(value)
end
wait_until(timeout = Capybara.default_wait_time) click to toggle source
# File lib/capybara/session.rb, line 244
def wait_until(timeout = Capybara.default_wait_time)
  WaitUntil.timeout(timeout,driver) { yield }
end
within(kind, scope=nil) click to toggle source
# File lib/capybara/session.rb, line 101
def within(kind, scope=nil)
  kind, scope = Capybara.default_selector, kind unless scope
  scope = XPath.from_css(scope) if kind == :css
  locate(:xpath, scope, "scope '#{scope}' not found on page")
  begin
    scopes.push(scope)
    yield
  ensure
    scopes.pop
  end
end
within_fieldset(locator) click to toggle source
# File lib/capybara/session.rb, line 113
def within_fieldset(locator)
  within :xpath, XPath.fieldset(locator) do
    yield
  end
end
within_frame(frame_id) click to toggle source
# File lib/capybara/session.rb, line 125
def within_frame(frame_id)
  driver.within_frame(frame_id) do
    yield
  end
end
within_table(locator) click to toggle source
# File lib/capybara/session.rb, line 119
def within_table(locator)
  within :xpath, XPath.table(locator) do
    yield
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.