DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

How does AI transform chaos engineering from an experiment into a critical capability? Learn how to effectively operationalize the chaos.

Data quality isn't just a technical issue: It impacts an organization's compliance, operational efficiency, and customer satisfaction.

Are you a front-end or full-stack developer frustrated by front-end distractions? Learn to move forward with tooling and clear boundaries.

Developer Experience: Demand to support engineering teams has risen, and there is a shift from traditional DevOps to workflow improvements.

Related

  • Required Capabilities in Self-Navigating Vehicle-Processing Architectures
  • 4 Types of JDBC Drivers [video]
  • Endpoint Security Controls: Designing a Secure Endpoint Architecture, Part 2
  • Building Resilient Networks: Limiting the Risk and Scope of Cyber Attacks

Trending

  • Effective Exception Handling in Java and Spring Boot Applications
  • Understanding the 5 Levels of LeetCode to Crack Coding Interview
  • Your Kubernetes Survival Kit: Master Observability, Security, and Automation
  • Debunking LLM Intelligence: What's Really Happening Under the Hood?
  1. DZone
  2. Data Engineering
  3. IoT
  4. Inspect Network Traffic in Capybara Using the Poltergeist Driver

Inspect Network Traffic in Capybara Using the Poltergeist Driver

In this post, we learn how to inspect network traffic of any page and validate its response values using these handy tools.

By 
Gowthamraj Palani user avatar
Gowthamraj Palani
·
Updated Oct. 01, 19 · Tutorial
Likes (4)
Comment
Save
Tweet
Share
14.2K Views

Join the DZone community and get the full member experience.

Join For Free

Ever tried inspecting the network traffic of any page and validating its response values? It's possible in Capybara if you are using the Poltergeist driver.

The Poltergeist driver is a PhantomJS driver for Capybara. It runs your tests in headless mode.

Network Tab in Developer Tools

If you are stuck up with any issues in any of the pages, you can open your dev tools and check the console errors or network traffic to understand the issue. This works if you are working on any browser.

Dev tools

What if You Are Running Your Capybara Tests?

All you need to do is add the below code:

page.driver.network_traffic

The above line will give you all network calls made during the page load with its headers that are difficult to read/manage.

Let's say you only want the list of URLs and their corresponding status. Just add two more lines of code as shown below:

page.driver.network_traffic.each do |request|
    request.response_parts.uniq(&:url).each do |response|
        puts "\n URL #{response.url}: \n Status #{response.status}"
    end
  end

The above code will give you the below output:

Image title

Get Response Headers

Suppose you want to get all the response headers of a page, the code looks like what I've got below:

page.driver.response_headers

Image title

You can also get the value of a specific header from the list. For example, if you want to validate the 'cache-control' header.

page.driver.response_headers['Cache-Control']

What Other Things Can We Do?

  • Check for any missing request/response strings.

  • Check for any 404s or any other errors in the page.

Code to Register Your Poltergeist Driver in Capybara

options = {}
Capybara.register_driver :poltergeist do |app|
  Capybara::Poltergeist::Driver.new(app, options)
end
Capybara.javascript_driver = :poltergeist
Capybara (software) Driver (software) Network

Opinions expressed by DZone contributors are their own.

Related

  • Required Capabilities in Self-Navigating Vehicle-Processing Architectures
  • 4 Types of JDBC Drivers [video]
  • Endpoint Security Controls: Designing a Secure Endpoint Architecture, Part 2
  • Building Resilient Networks: Limiting the Risk and Scope of Cyber Attacks

Partner Resources

×

Comments

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • [email protected]

Let's be friends: