wdio-intercept-service icon indicating copy to clipboard operation
wdio-intercept-service copied to clipboard

How to intercept Graphql request?

Open ThiagoMFerreira opened this issue 5 years ago • 7 comments

Hello, I need to intercept Grahpql requests to my tests, but this is fetch type, so the Intercept service isn't getting the request, is there any way to intercept this request?

the request is returning the result of this way data: {values: {totalPages: 10,…}},…} data: {values: {totalPages: 10,…}} values: {totalPages: 10,…}

Thank You.

ThiagoMFerreira avatar Oct 16 '20 17:10 ThiagoMFerreira

Hey @ThiagoMFerreira, did you had any progress with this kind of tests? I believe I'm having the same issues.

It doesn't catch graphql requests, although they're shown in the network tab.

ruancarvalho avatar Nov 13 '20 12:11 ruancarvalho

Hey @ThiagoMFerreira, did you had any progress with this kind of tests? I believe I'm having the same issues.

It doesn't catch graphql requests, although they're shown in the network tab.

Hi @ruancarvalho any progress yet 😔

ThiagoMFerreira avatar Nov 13 '20 13:11 ThiagoMFerreira

GraphQL requests are not particularly special. This plugin has been supporting fetch since v3 (https://github.com/chmanie/wdio-intercept-service/blob/master/CHANGELOG.md#---300--13022019). Have you noticed this:

There's one catch though: you can't intercept HTTP calls that are initiated on page load (like in most SPAs), as it requires some setup work that can only be done after the page is loaded (due to limitations in selenium). That means you can just capture requests that were initiated inside a test.

chmanie avatar Mar 31 '21 09:03 chmanie

Hey @chmanie Even though my requests happens inside my test, it does not capture the Grapqh requests. Do you have any thoughts about it?

andreluisce avatar Jul 01 '21 09:07 andreluisce

@andreluisce are the requests issued from an iframe?

tehhowch avatar Oct 27 '21 03:10 tehhowch

I had same problem when trying intercepting graphql request which it would return JSON data. it seems interceptor didnt recognised the requests as ajax calls at all

trietnguyen267 avatar Nov 11 '21 20:11 trietnguyen267

@trietnguyen267 I had the same problem. Solved it using the mock function https://webdriver.io/docs/mocksandspies/#spies

You are able to mock the graphql requests and then create a helper function to validate what you want based on the operationName.

const mocks = await browser.mock('**/graphql', { method: 'post' })

console.log(mock.calls[0].postData)

PeterPimentel avatar Jun 09 '22 10:06 PeterPimentel