Skip to content

About

HTTPX driver for Capybara, allowing testing of REST APIs

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Capybara-HTTPX

Build Status

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.

Installation

gem install capybara-httpx

Or add capybara-httpx to your Gemfile. HTTPX is installed as a runtime dependency.

Usage

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 /users

The 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)
end

Array query parameters use HTTPX-style bracket notation by default. The params_encoding driver setting can also be set to :rack, :multi, or :none.

Running tests

bundle install
bundle exec rake

CI runs the test suite on currently supported Ruby release series: 3.4, 4.0, and 4.1.

License

Copyright (c) 2010 Tron Jonathan and HALTER Joseph. See LICENSE for details.

About

HTTPX driver for Capybara, allowing testing of REST APIs

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages