Parent

Webrat::SeleniumSession

Public Instance Methods

automate() click to toggle source
# File lib/webrat/selenium/selenium_session.rb, line 41
def automate
  yield
end
check(label_text) click to toggle source
# File lib/webrat/selenium/selenium_session.rb, line 131
def check(label_text)
  locator = "webrat=#{label_text}"
  selenium.wait_for_element locator, :timeout_in_seconds => 5
  selenium.click locator
end
Also aliased as: uncheck
choose(label_text) click to toggle source
# File lib/webrat/selenium/selenium_session.rb, line 123
def choose(label_text)
  locator = "webrat=#{label_text}"
  selenium.wait_for_element locator, :timeout_in_seconds => 5
  selenium.click locator
end
click_button(button_text_or_regexp = nil, options = {}) click to toggle source
# File lib/webrat/selenium/selenium_session.rb, line 71
def click_button(button_text_or_regexp = nil, options = {})
  if button_text_or_regexp.is_a?(Hash) && options == {}
    pattern, options = nil, button_text_or_regexp
  elsif button_text_or_regexp
    pattern = adjust_if_regexp(button_text_or_regexp)
  end
  pattern ||= '*'
  locator = "button=#{pattern}"

  selenium.wait_for_element locator, :timeout_in_seconds => 5
  selenium.click locator
end
current_url() click to toggle source
# File lib/webrat/selenium/selenium_session.rb, line 67
def current_url
  selenium.location
end
fill_in(field_identifier, options) click to toggle source
# File lib/webrat/selenium/selenium_session.rb, line 51
def fill_in(field_identifier, options)
  locator = "webrat=#{field_identifier}"
  selenium.wait_for_element locator, :timeout_in_seconds => 5
  selenium.type(locator, "#{options[:with]}")
end
fire_event(field_identifier, event) click to toggle source
# File lib/webrat/selenium/selenium_session.rb, line 140
def fire_event(field_identifier, event)
  locator = "webrat=#{Regexp.escape(field_identifier)}"
  selenium.fire_event(locator, "#{event}")
end
key_down(field_identifier, key_code) click to toggle source
# File lib/webrat/selenium/selenium_session.rb, line 145
def key_down(field_identifier, key_code)
  locator = "webrat=#{Regexp.escape(field_identifier)}"
  selenium.key_down(locator, key_code)
end
key_up(field_identifier, key_code) click to toggle source
# File lib/webrat/selenium/selenium_session.rb, line 150
def key_up(field_identifier, key_code)
  locator = "webrat=#{Regexp.escape(field_identifier)}"
  selenium.key_up(locator, key_code)
end
response() click to toggle source
# File lib/webrat/selenium/selenium_session.rb, line 59
def response
  SeleniumResponse.new(self, response_body)
end
save_and_open_screengrab() click to toggle source
# File lib/webrat/selenium/selenium_session.rb, line 202
def save_and_open_screengrab
  return unless File.exist?(Webrat.configuration.saved_pages_dir)

  filename = "#{Webrat.configuration.saved_pages_dir}/webrat-#{Time.now.to_i}.png"

  if $browser.chrome_backend?
    $browser.capture_entire_page_screenshot(filename, '')
  else
    $browser.capture_screenshot(filename)
  end
  open_in_browser(filename)

end
select(option_text, options = {}) click to toggle source
# File lib/webrat/selenium/selenium_session.rb, line 108
def select(option_text, options = {})
  id_or_name_or_label = options[:from]

  if id_or_name_or_label
    select_locator = "webrat=#{id_or_name_or_label}"
  else
    select_locator = "webratselectwithoption=#{option_text}"
  end

  selenium.wait_for_element select_locator, :timeout_in_seconds => 5
  selenium.select(select_locator, option_text)
end
selenium() click to toggle source
# File lib/webrat/selenium/selenium_session.rb, line 193
def selenium
  return $browser if $browser
  setup
  $browser
end
simulate() click to toggle source
# File lib/webrat/selenium/selenium_session.rb, line 38
def simulate
end
uncheck(label_text) click to toggle source
Alias for: check
visit(url) click to toggle source
# File lib/webrat/selenium/selenium_session.rb, line 45
def visit(url)
  selenium.open(url)
end
wait_for(params={}) click to toggle source
# File lib/webrat/selenium/selenium_session.rb, line 155
def wait_for(params={})
  timeout = params[:timeout] || 5
  message = params[:message] || "Timeout exceeded"

  begin_time = Time.now

  while (Time.now - begin_time) < timeout
    value = nil

    begin
      value = yield
    rescue Exception => e
      unless is_ignorable_wait_for_exception?(e)
        raise e
      end
    end

    return value if value

    sleep 0.25
  end

  error_message = "#{message} (after #{timeout} sec)"
  
  if $browser && Webrat.configuration.selenium_verbose_output
    error_message += HTML of the page was:#{selenium.get_html_source}"
  end

  raise Webrat::TimeoutError.new(error_message)
  true
end

Protected Instance Methods

create_browser() click to toggle source
# File lib/webrat/selenium/selenium_session.rb, line 238
def create_browser
  $browser = ::Selenium::Client::Driver.new(
    Webrat.configuration.selenium_server_address || "localhost",
    Webrat.configuration.selenium_server_port,
    Webrat.configuration.selenium_browser_key,
    "http://#{Webrat.configuration.application_address}:#{Webrat.configuration.application_port_for_selenium}"
  )
  $browser.set_speed(0) unless Webrat.configuration.selenium_server_address

  at_exit do
    silence_stream(STDOUT) do
      $browser.stop
    end
  end
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.