Easily Generate Mock HTTP Response for TestCafe - testing

I am attempting to mock some responses in TestCafe and mocking the responses is pretty slow going. The workflow I would like is something like this:
Walk through a test scenario in Chrome.
Copy the selected network request to mock as a curl command.
Paste it in to a curl command to Testcafe translator.
Paste it in to testcafe.
I haven't found a good way to generate mock requests other than manually typing them out by hand. Is anyone aware of any tools which allow you to translate a fetch or curl command to TestCafe mock response?

The RequestMock.onRequestTo method gives an ability to identify and filter requests by their urls or parameters. You can simply copy a request url and response body from the Chrome DevTools Network tab and pass them to the onRequestTo and respond methods.

Related

Does TestCafe RequestMock Stop the Original Request

When implementing a RequestMock in TestCafe does the original request still get made and completed and then modified by TestCafe or does TestCafe intercept the request and stop the original?
I'm asking because we are thinking about using this feature to mock some requests to speed up testing, such as mocking images. However, if the original request still has to be completed before the mock then this does not seem like a viable solution.
RequestMock intercepts requests to a web resource and emulates a response, so the original request is not performed. Please refer to the documentation for more information.

Insomnia same request with different data

I'am trying to write unit tests for each one of my requests in insomnia.
Is there a way to access the request in javascript and modify the body/query params? I want to test the different edge cases.
Are the insomnia js functions documented anywhere?

API requires HMAC authentication JMeter

I am getting error when setting up API test in Jmeter, same is working fine in POSTMAN.
Using HMAC authentication.
I have some basic knowledge of Jmeter new to the tool.
https://developer.firstdata.com/marketplace/api/authentication.html?shell#authentication.
Postman Pre-request Script
And Postman Header details
Postman API response is working fine.
Same as been work in Jmeter but I' getting response message as {"message":"HMAC signature cannot be verified, a valid date or x-date header is required for HMAC Authentication"}
I have added JSR223 PostProcessor and HTTP Header Manager.
and here are the details for both image attached below.
** JMeter - JSR223 PostProcessor**
JMeter HTTP Header Manager
Copying and pasting code from Postman won't work in JMeter because:
Postman is a browser extension and is capable of executing JavaScript and according to JMeter project main page:
JMeter is not a browser, it works at protocol level. As far as web-services and remote services are concerned, JMeter looks like a browser (or rather, multiple browsers); however JMeter does not perform all the actions supported by browsers. In particular, JMeter does not execute the Javascript found in HTML pages. Nor does it render the HTML pages as a browser does (it's possible to view the response as HTML etc., but the timings are not included in any samples, and only one sample in one thread is ever displayed at a time).
If you're trying to run JavaScript code you need to choose the appropriate language from the dropdown
JMeter doesn't include CryptoJS library, you will need to download it and load before running the JavaScript
Since JMeter 3.1 it's recommended to use Groovy language for scripting as this option provides maximum performance especially when it comes to "heavy" cryptographic operations so I would recommend re-writing your code in Groovy
I see you like screenshots so I include an example implementation as a screenshot here:
More information on Groovy scripting in JMeter: Apache Groovy - Why and How You Should Use It

Set request header and User Agent in Geb

When using Geb, is it possible to set custom request headers and user agent when using the Browser API (and not the Direct Download API)?
While this is possible with the FirefoxDriver (see here), I am looking for a way of doing this with the WebKitDriver.
A possible solution is via a proxy.
BrowserMob has a standalone mode with REST api, or embedded in your test programmatically: https://github.com/webmetrics/browsermob-proxy . Useful when there are a lot of custom headers you want to test.
If you already have Apache, you can create another VirtualHost on a different port having that particular request header, and point your browser to that port before the test. Given that your header doesn't change between tests.
This might not be the direct solution to your question: modify request headers directly in Browser API, but it achieves the end result.

downloading file using curl

I have a quite simple task:
i need to download file from a web page. In browser, it is done by pressing submit button. Just simple button, press it and you see the pop-up window asking where to save file and so on. Data is sent to server via post method.
I tried POST'ing with curl like: curl -d "foo=bar&....." [URL]
but this request returns the page itself, not the file. And I am quite confused about how to get the file, since I dont know it's adress on server and the only way to get it is to press this freaking button.
Please help
If you use unix-like os system you can use wireshark by simple apply filter "http", or some other software, e.g. tcpdump.
if you under ms windows, fiddler2 is very good tools.
first,
use this kind tools get the accurate information about the tracfic.
then analyze the http request, especially the rquest cookies header.
finally, struct your own request by curl.
the foo=bar&.....
is only the content of the request. you may also attention the header of the request.
or your can post your url, so that other peoplle can help you analyze the stuff.
Use Wireshark or a browser plugin that captures the http request sent on submit, then use curl or, for example, PHP's file_get_contents() to emulate the request.