webdriverio-community / wdio-intercept-service

🕸 Capture and assert HTTP ajax calls in webdriver.io
MIT License
105 stars 33 forks source link

Is there a way to abort the request? #455

Open amirhoseinsalimi opened 1 year ago

amirhoseinsalimi commented 1 year ago

Hi, I want to have the ability to abort the requests while testing so they don't get to the API server. Is there a way to do so?

Currenlty what I see is that requets are made to the server and 200 returns. I don't want to bother myself to check if the API server responds or not, I just want to make sure that the requets is being made.

Is there an API for this?

erwinheitzman commented 1 year ago

Not that I know of

christian-bromann commented 1 year ago

Afaik there is, just not using this service. WebdriverIO has some native capabilities like the abort command that would allow this but these can only be run through the Devtools protocol which has its limitations.

tehhowch commented 1 year ago

The approach taken by my coworkers has been to do something similar to what this service does: wrap the fetch / XMLHttpRequest object, filter the incoming URLs, and redirect / cancel them / etc as desired. That obviously only works when you get a chance to invoke your filter before the requests you'd like to block are made.

However, if you don't need to block the requests, just check they were made, then you can use getRequests and perform your own matching on the returned objects. Right now the service requires you to specify the status code in order to use its assert functionality.

A PR extending the capability to match just the method & url is welcomed!

SubhenduShekhar commented 1 year ago

You can write a custom command. Grab the sessionId using browser.sessionId and implement your actions using the jsonwire protocol. I have done it in multiple scenarios and it has worked flawlessly.