Last active
November 15, 2017 00:41
-
-
Save sdelrio0/5238d08b78d249af73803a60287cc12d to your computer and use it in GitHub Desktop.
Standalone Capybara
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# config/initializers/capybara.rb | |
require 'capybara' | |
require 'capybara/dsl' | |
require 'selenium/webdriver' | |
# Use Chrome as the selenium test driver | |
Capybara.register_driver :headless_chrome do |app| | |
capabilities = Selenium::WebDriver::Remote::Capabilities.chrome( | |
chromeOptions: { args: %w(headless disable-gpu) } | |
) | |
Capybara::Selenium::Driver.new( | |
app, | |
browser: :chrome, | |
desired_capabilities: capabilities | |
) | |
end | |
Capybara.javascript_driver = :headless_chrome | |
Capybara.raise_server_errors = false | |
Capybara.run_server = false | |
Capybara.current_driver = :headless_chrome | |
Capybara.app_host = 'http://localhost' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gem 'capybara-selenium' | |
gem 'chromedriver-helper' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include Capybara::DSL | |
visit 'http://www.google.com' | |
search_box = find('[title="Search"]') | |
search_box.send_keys ['What is the meaning of life?', :return] | |
page.save_screenshot | |
# ... |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment