Test Data Setup Using APIs | Bondar Academy
Course: Cypress UI Testing with JavaScript
Module: Working with APIs
Instructor: Artem Bondar
Lesson Summary
In this lesson, we explore how to use Cypress for setting up test data through APIs . The goal is to create an article, modify it, add comments, and then delete it, specifically focusing on the deletion process. Key Steps in the Process Creating an Article via API: Instead of using the UI to create an article, we utilize the API for a faster setup. Using cy.request : This method is essential for making API calls in Cypress. We prefer using an object to provide arguments for better readability. Authentication: The first step is to authenticate and obtain a token from the login endpoint. This involves: Making a POST request to the login URL. Validating the response status code (should be 200). Extracting the token from the response for future requests. Creating the Article: After obtaining the token, we make another POST request to create the article with the necessary headers. Deleting the Article: We then perform UI actions to delete the article and validate that it no longer exists. Important Considerations Always validate the status code after each API request to ensure success. Use cy.intercept and cy.wait to handle asynchronous operations and ensure proper validation after deletion. For practice, create a UI scenario to add a new article, followed by an API call to delete it, reinforcing the concepts learned in this lesson.