2

My application is making an XHR POST that I need to either fail on purpose or be skipped completely. The test is to run a scenario where the service I am requesting is unavailable.

This has to be done in the browser, I don't have the access to make a coding change to do this, nor the firewall. This asnyc XHR call will happen on transition from one tile to another in a single page web app, along with other XHR calls

So far I have used firebug's XHR breakpoint, but I have already got a successfull response when the breakpoint kicks in.

Any other ways to do this?

larrydalmeida
  • 1,570
  • 3
  • 16
  • 31
andy mccullough
  • 9,070
  • 6
  • 32
  • 55

4 Answers4

3

An easy way to do this is by using Fiddler. Install, click on the AutoResponder tab, check "Enable Rules" and "Unmatched Requests pass through", in the rule editor specify url you need to test for response failure and add the rule "*drop".

Fiddler will immediately close the connection when you request this url.

Example usage - if I wanted to simulate failure of the ajax request for the USA Today sports section:

enter image description here

Now the http://www.usatoday.com/sports/ would never load as the ajax request will fail.

enter image description here

More details here.

Similar question already answered here.

Community
  • 1
  • 1
larrydalmeida
  • 1,570
  • 3
  • 16
  • 31
2

Google Chrome developer tools allows you to do this via 'Request Blocking'. This essentially allows you to refresh your page while blocking a specific resource from being loaded. You can find more details in this fleshed out answer: https://stackoverflow.com/a/32459616/823549

1000Nettles
  • 2,314
  • 3
  • 22
  • 31
1

Just use this file as request receiver... (send your request to send.php).

send.php

<php
  header('HTTP/1.0 403 Forbidden');
  echo "HTTP Error occured!";
?>

PS. You can use different errorcodes:

403 - forbidden

404 - not found

503 - service temporary unavailable

Full_List_of_HTTP_status_codes

Flash Thunder
  • 11,672
  • 8
  • 47
  • 91
  • I cant make any code changes, the code has been deployed to a test environment out of my hands as part of a large enterprise app, unfortunately I can't make small code updates and redeploys – andy mccullough Dec 12 '14 at 13:55
  • 1
    So simply make a request to non-existing file, it will return `404` error. Or request to file from other server ... it will return `Client Access Denied` error (browser cross domain policy). – Flash Thunder Dec 12 '14 at 13:55
  • can this setup through any browser developer tools, before the call has started? I added some more info in the original post. I dont have exact control on when the call happens, it will occur between tile(page) transitions within a single page web app, along with other async XHR calls – andy mccullough Dec 12 '14 at 14:00
  • 1
    You can edit a script in browser - in Chrome for example you set debug point at first line, it stops there, then u modify js in code and hit continue button. Or you can change the host file to redirect request to your server, if the domain of XHR request is different than main site (for example it's subdomain) ... if not, only first option applies. More info about Chrome method here: http://stackoverflow.com/questions/5067532/editing-in-the-chrome-debugger – Flash Thunder Dec 12 '14 at 14:04
  • thanks, great help. A minified and combined JS file doesnt help :( i'll keep looking – andy mccullough Dec 12 '14 at 14:10
0

If you want to simulate any failure then simply go offline. Request will time out and fail.

Konrad Dzwinel
  • 36,825
  • 12
  • 98
  • 105