Search code examples
ruby-on-railsseleniumrspeccapybara

When testing in Rspec do I get VCR to pick up an external API call in Javascript / Capybara / Selenium?


I'm using rspec and VCR to test API calls. All of the VCR cassettes are recording correctly on the server side of the code.

However I have an api call in the browser (with js: true) running. The api call looks like this

xhttp.open("GET", "https://someapi.com/someaddress/123456789/an-action", true);

This API call is going to the live website, and is not being picked up and recorded by VCR.

I was wondering how do I go about getting a VCR to recored and play back to the JS API call? So it acts the same as the server ones.


Solution

  • VCR can't pick up calls made from the browser - it only has access to calls made from your application. You need to use a programmable proxy to do something like that. See something like https://github.com/oesmith/puffing-billy