docs/guides/networking/capybara.md in wayfarer-0.4.6 vs docs/guides/networking/capybara.md in wayfarer-0.4.7
- old
+ new
@@ -1,71 +1,62 @@
# Capybara
-[Capybara](https://github.com/teamcapybara/capybara) is originally a test
-framework for web applications.
+[Capybara](https://github.com/teamcapybara/capybara) is a test framework for web
+applications which adds a nice API that also works well for web scraping.
-When Capybara is in use, a remote browser process is available as a Capybara
-session:
-
```ruby
-Wayfarer.config.network.agent = :capybara
-# Wayfarer.config.capybara.driver = ...
+Wayfarer.config[:network][:agent] = :capybara
+# Wayfarer.config[:capybara][:driver] = ...
class DummyJob < Wayfarer::Worker
- route { to :index }
+ route.to :index
def index
browser # => #<Capybara::Session ...>
end
end
```
+## Example: Automating Chrome with Cuprite and Ferrum
-## Configuring a driver
+1. Install the [Curpite](https://github.com/rubycdp/cuprite) Capybara driver:
-1. Install the Capybara driver for the desired user agent.
-
- For example, to automate Google Chrome with
- [Ferrum](https://github.com/rubycdp/ferrum), install the
- [Cuprite](https://github.com/rubycdp/cuprite) driver:
-
=== "RubyGems"
```ruby
gem install cuprite
```
- === "Bundler"
+ === "Gemfile"
```ruby
gem "cuprite" # Gemfile
```
-2. Configure Wayfarer to use the `:capybara` user agent and set the desired
- driver:
+2. Configure Wayfarer to use the `:capybara` user agent and set the driver:
=== "Runtime"
```ruby
- Wayfarer.config.network.agent = :capybara
- Wayfarer.config.capybara.driver = :cuprite
+ Wayfarer.config[:network][:agent] = :capybara
+ Wayfarer.config[:capybara][:driver] = :cuprite
```
=== "Environment variables"
```ruby
WAYFARER_NETWORK_AGENT=capybara
WAYFARER_CAPYBARA_DRIVER=cuprite
```
-3. Register the driver:
+3. Register the driver with Capybara:
```ruby
require "capybara/cuprite"
Capybara.javascript_driver = :cuprite
Capybara.register_driver(:cuprite) do |app|
# Wayfarer's Ferrum or Selenium options can be passed along
- Capybara::Cuprite::Driver.new(app, Wayfarer.config.ferrum.options)
+ Capybara::Cuprite::Driver.new(app, Wayfarer.config[:ferrum][:options])
end
```