How to use Capybara in pure Ruby (without Rails)?

对着背影说爱祢 提交于 2019-12-02 17:05:23
Pål Brattberg

Here's something that seems to work for me:

require 'rubygems'
require 'capybara'
require 'capybara/dsl'

Capybara.run_server = false
Capybara.current_driver = :selenium
Capybara.app_host = 'http://www.google.com'

module MyCapybaraTest
  class Test
    include Capybara::DSL
    def test_google
      visit('/')
    end
  end
end

t = MyCapybaraTest::Test.new
t.test_google

It goes to show that even incorrect documentation lives forever. The Capybara README used to recommend to include Capybara in the global namespace, this is a really bad idea, and messes up any number of random things. You should include Capybara in your own module or class and use that instead.

Check out the README for current best practices.

Please check this CapybaraRspec101 example and fork it.

It's a small example for acceptance tests on http://www.hi5.com using from scratch:

  • Capybara
  • Rspec
  • Selenium-webdriver

All instructions are in the repo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!