I have been exploring the projects on GitHub which demonstrates the capabilities of integrating TestCafe with CucumberJS, however, I am not able to find any reference to test the RestAPI through this integration and I need it as per my project requirements.
Can I request someone to post a working example, currently I am exploring the following repo: https://github.com/rquellh/testcafe-cucumber
I have already tried to explore the projects available on GitHub:
https://github.com/search?p=3&q=testcafe+cucumber&type=Repositories
I am expecting the Cucumber BDD driven workflow based on TestCafe:
https://devexpress.github.io/testcafe/documentation/test-api/intercepting-http-requests/
There are two options here.
If you want to test RestAPI itself by sending requests from a test scenario and checking a response, you don't need TestCafe for this. According to this issue TestCafe still cannot make HTTP requests. Furthermore, Request Handlers cannot handle requests you make from your test code using external tools. They work only for requests that a testing page makes.
If a script on your testing page makes RestAPI requests and you want to know what is in response, you can just add a request logger like this:
let requestLogger = null;
Given('I use example.com REST API', async function () {
requestLogger = RequestLogger(/https:\/\/api\.example\.com/, {
logResponseHeaders: true,
logResponseBody: true
});
await testController.addRequestHooks(requestLogger);
});
And then you can obtain data from requestLogger
as described in the Test API documentation.