Skip to content

Instantly share code, notes, and snippets.

@BenHall
Created January 10, 2010 02:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BenHall/273302 to your computer and use it in GitHub Desktop.
Save BenHall/273302 to your computer and use it in GitHub Desktop.
Hack to make the Webrat Selenium API work for within
# Taken from https://gist.github.com/225061/2ecbd30eb13ca1edbb918249d0e834964ab58d6b
module Webrat
class SeleniumSession
extend Forwardable
# Add more methods of webrat/core/session when needed
def_delegators :current_scope, :field_labeled, :table_at, :css_search
def within(selector)
scopes.push(Webrat::Scope.from_scope(self, current_scope, selector))
ret = yield(current_scope)
scopes.pop
return ret
end
def current_scope
scopes.last || page_scope
end
def page_scope
Webrat::Scope.from_page(self, response, response_body)
end
def scopes
@_scopes ||= []
end
def xml_content_type?
false
end
def current_dom #:nodoc:
current_scope.dom
end
def elements
{}
end
end
class Scope
def selenium
return @session.response
end
end
class SeleniumResponse
def is_text_present(text_finder)
puts text_finder
body.include? text_finder
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment