Skip to content

Latest commit

 

History

History
43 lines (31 loc) · 963 Bytes

standalone.md

File metadata and controls

43 lines (31 loc) · 963 Bytes

Using the DSL elsewhere

You can mix the DSL into any context by including Capybara::DSL:

require 'capybara'
require 'capybara/dsl'

Capybara.default_driver = :webkit

module MyModule
  include Capybara::DSL

  def login!
    within("//form[@id='session']") do
      fill_in 'Login', :with => 'user@example.com'
      fill_in 'Password', :with => 'password'
    end
    click_link 'Sign in'
  end
end

This enables its use in unsupported testing frameworks, and for general-purpose scripting.

Using the sessions manually

For ultimate control, you can instantiate and use a Session manually.

require 'capybara'

session = Capybara::Session.new(:webkit, my_rack_app)
session.within("//form[@id='session']") do
  session.fill_in 'Login', :with => 'user@example.com'
  session.fill_in 'Password', :with => 'password'
end
session.click_link 'Sign in'