A Capybara driver that uses HTTPX to make HTTP requests to a Rack application, including applications running on a remote host. This project is based on TalentBox/capybara-typhoeus, with HTTPX replacing Typhoeus as its HTTP client.
This driver is intended for testing APIs. It does not implement browser features such as JavaScript, clicking controls, or submitting forms through the DOM.
gem install capybara-httpxOr add capybara-httpx to your Gemfile. HTTPX is installed as a runtime
dependency.
require "capybara/httpx"
session = Capybara::Session.new(:httpx, app)
session.get "/users"For remote testing, configure the host as usual:
Capybara.app_host = "https://api.example.com"The driver can also be selected in Cucumber using the @httpx tag. Require
capybara/httpx/cucumber from env.rb:
require "capybara/httpx/cucumber"@httpx
Scenario: request API data
When I send a GET request to /usersThe driver provides authenticate_with, request_body, and as= helpers on
its session. Request options set through driver.with_options are passed to
HTTPX. The default request timeout is three seconds and can be customized when
registering a driver:
Capybara.register_driver :httpx_with_custom_timeout do |app|
Capybara::HTTPX::Driver.new(app, timeout: 1)
endArray query parameters use HTTPX-style bracket notation by default. The
params_encoding driver setting can also be set to :rack, :multi, or
:none.
bundle install
bundle exec rakeCI runs the test suite on currently supported Ruby release series: 3.4, 4.0, and 4.1.
Copyright (c) 2010 Tron Jonathan and HALTER Joseph. See LICENSE for details.