README.rdoc in capybara-0.3.8 vs README.rdoc in capybara-0.3.9
- old
+ new
@@ -6,11 +6,12 @@
Capybara aims to simplify the process of integration testing Rack applications,
such as Rails, Sinatra or Merb. It is inspired by and aims to replace Webrat as
a DSL for interacting with a webapplication. It is agnostic about the driver
running your tests and currently comes bundled with rack-test, Culerity,
-Celerity and Selenium support built in.
+Celerity and Selenium support built in. env.js support is available as the
+{capybara-envjs gem}[http://github.com/smparkes/capybara-envjs].
== Install:
Install as a gem:
@@ -121,10 +122,20 @@
== Culerity
Install celerity as noted above, make sure JRuby is in your path. Note that
Culerity doesn't seem to be working under Ruby 1.9 at the moment.
+== env.js
+
+The {capybara-envjs driver}[http://github.com/smparkes/capybara-envjs]
+uses the envjs gem ({GitHub}[http://github.com/smparkes/env-js],
+{rubygems.org}[http://rubygems.org/gems/envjs]) to interpret
+JavaScript outside the browser. The driver is installed by installing the capybara-envjs gem:
+ gem install capybara-envjs
+More info about the driver and env.js are available through the links above. The envjs gem only supports
+Ruby 1.8.7 at this time.
+
== The DSL
Capybara's DSL is inspired by Webrat. While backwards compatibility is retained
in a lot of cases, there are certain important differences.
@@ -139,10 +150,14 @@
visit(post_comments_path(post))
The visit method only takes a single parameter, the request method is *always*
GET.
+You can get the current path of the browsing session for test assertions:
+
+ current_path.should == post_comments_path(post)
+
=== Clicking links and buttons
You can interact with the webapp by following links and buttons. Capybara
automatically follows any redirects, and submits forms associated with buttons.
@@ -194,10 +209,21 @@
within_table('Employee') do
fill_in 'Name', :with => 'Jimmy'
end
+You can also specify a scope to be used for future searches with the <tt>scope_to</tt>.
+It returns a handle to the session scoped to the provided selector.
+
+ scope = page.scope_to("//div[@id='foo']")
+ scope.has_xpath("//a[@class='bar']")
+
+You can also chain scopes by calling <tt>scope_to</tt> on an existing scope.
+
+ more_scope = scope.scope_to("//p")
+ more_scope.has_xpath("//a[@class='baz']")
+
=== Querying
Capybara has a rich set of options for querying the page for the existence of
certain elements, and working with and manipulating those elements.
@@ -226,10 +252,15 @@
locate("//*[@id='overlay'").find("//h1").click
all('a').each { |a| a[:href] }
=== Scripting
-In drivers which support it, you can easily evaluate JavaScript:
+In drivers which support it, you can easily execute JavaScript:
+
+ page.execute_script("$('body').empty()")
+
+For simple expressions, you can return the result of the script. Note
+that this may break with more complicated expressions:
result = page.evaluate_script('4 + 4');
=== Debugging