Home > Software design >  When testing in Rspec do I get VCR to pick up an external API call in Javascript / Capybara / Seleni
When testing in Rspec do I get VCR to pick up an external API call in Javascript / Capybara / Seleni

Time:01-26

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.

CodePudding user response:

I'm unable to add a comment, did you try adjusting these options: match_requests_on: %i[method headers]

https://relishapp.com/vcr/vcr/v/1-6-0/docs/cassettes/request-matching

You could try disconnecting from the internet and check if it works locally.

CodePudding user response:

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

  •  Tags:  
  • Related