Cypress intersepting Google maps requests

Hi. I’m new to Cypress and testing in general. I am working for a small start-up and was asked to minimize amount of google requests done by tests.
My first attempt would be:

cy.intercept(“GET”, “*”, { fixture: ‘getpredictionsgoogle’})

But it’s not as simple. It seems like authentication happens before the first character is typed. During authentication certain token is assigned, but this token doesn’t match tokens used for prediction requests which are different after each character typed in. The process ends with get place details request.

1 Like

Welcome @antonbdnk,

I haven’t worked with Google Maps automation before but I can’t see a tonne of network traffic when searching. Instead of intercepting the request you do want, it might be easier to block/abort the ones you don’t care about - Is there a possibility to test blocked network requests in Cypress? - Stack Overflow.

Not sure how Google Maps will behave when you start blocking requests but it could work out easier. There might be a bit of trial and error involved.

1 Like

I’m not sure I understand the goal. Do you want to check the Google Maps integration?
This can be useful as a quick overview for others:

  • Usage is tracked for each Product SKU.
  • A SKU is the combination of the Product API + the service or function called (for example, Places API - Place Details).
  • A product may have multiple SKUs billed at different rates (for example, Places API - Place Details; Places API - Autocomplete - Per Request).
  • SKU pricing is tiered, based on volume of use, with three tiers: 0–100,000; 100,001–500,000; 500,001+.
  • Cost is calculated by SKU Usage x Price per each use.

Some ways to go about it:

  • One way that comes to mind is to check it through the backend: analytics for example; one of them being directly their console: The Cloud Console APIs & Services report
  • Or have the devs log the app Google Maps API calls and you create a script to dive into the logs and extract and analyze the Google Maps responses.
  • Or just try to work around the above overview from the UI/API optimizing the calls based on the actual risks you see coming for your app/business. I would check as well the specific type of payment per API for each request… as listed here:
    Places API Usage and Billing  |  Google for Developers
  • You could evaluate how many calls you make and their pricing; the total amount could be smaller than the others assume. Or if it’s still to large, run the Maps checks less often. Say, your automation does 20 requests per suite run to the autocomplete-api, you run it once per hour, 24 times per day, for 30 days in a month. That’s 14.400 requests or 41 euros. Run it once a day instead of per hour, so the cost is <2 euro/month.
1 Like