Is Cypress a good choice for API Automation Testing than Rest Assured/Karate? [closed]
Asked Answered
H

2

5

I have been googling about using Cypress for Automation API testing. I found below links:

Most of the cases I can think of like Oauth, All REST Methods including Form-data, GraphQL, Assertions, mocking can be achieved using Cypress. However I was wondering why its not being used and is it a good choice over other tools? Please suggest!

Thanks a lot in Advance.

Homicidal answered 13/10, 2021 at 6:56 Comment(1)
See my comment below. Loading the browser to test the backend is an automatic deal killer. Nothing will ever change that.Federal
S
7

Ask these questions and you will get the answer:

  • How easy is it to chain API requests and feed the response of one request into the next?
  • How easy is it to create data-driven tests? Which is to loop over a tabular set of data and make requests to the same end-point.
  • Can you run your tests in parallel? (Without having to pay extra)
  • And when you run tests in parallel, do you get a single aggregate HTML report?
  • Can you mix async operations (e.g. message queues, API hooks / call-backs) into your test suites?
  • Can you mix database calls into your test suites and assertions?
  • Can you assert "deeply" on response payloads, and easily ignore (or just check formats for) any data-values that are random, such as time-stamps and generated id-s?
  • Can you re-use your functional API tests as performance tests?
  • Can you step-through and debug your API tests using an IDE?
  • Can you write mocks in the same framework, that you can then use to replace services you depend on in your end-to-end tests?

I've found very few frameworks that can actually do all the above. You can do the research :)

Sabinesabino answered 13/10, 2021 at 7:27 Comment(0)
B
5

I currently work with Cypress only for api testing (a decision made by the company). There's no right or wrong answer. If it's the tool you want to use and you are comfortable with it, then go for it.

That being said, take into account that Cypress is a framework designed to do end to end or even component testing and therefore, even when you do not have a UI, it will always use the browser to perform actions (this in the long term, and depending the amount of tests, can have an impact in the run time). Lots of things are designed to interact with ui components and you need to patch/wrap your way to perform more complex stuff.

I personally had some issues with nested requests, or when having to perform multiple actions with responses. Asynchrony in general (handled in a weird way by cypress in my opinion).

If I could choose, I would go with a framework designed for api testing just because it will be more flexible and probably will have more tools for you to use when dealing with some of the things I mentioned above.

Hope this helps and good luck!

Benefaction answered 13/10, 2021 at 7:14 Comment(2)
I'm sorry, but when you're talking about avg image build times of 45 seconds for Cypress, there is definitely a wrong answer. API suites run faster than the time it takes to build Cypress. It's loading a browser every test for a test type that specifically targets the backend. We used Cypress for UI and end-to-end smoke tests. But for API we went with SuperTest and Jest for the reasons I just mentioned.Federal
@Federal you are correct and I agree 100%. What I meant with no wrong answer is that it always depend on the case. If they want to evaluate if a response has a 200 status or not, have 2 tests and everything else mounted in cypress, then timing won't be relevant hereBenefaction

© 2022 - 2024 — McMap. All rights reserved.