Validation Using APIs | Bondar Academy
Course: Mastering testRigor
Module: Working with APIs
Instructor: Artem Bondar
Lesson Summary
In this lesson, we explore a practical use case of utilizing APIs in Test Trigger for validating test data when a UI is not available. This approach is particularly useful when you need to confirm the existence of data after test execution without a graphical interface. Key Concepts Scenario Overview: We previously created and published an article, validating its presence on the UI. However, in cases where the UI lacks validation pages, we can rely on API calls. API Validation: Instead of checking the UI, we will use API calls to confirm that the article was created in the backend. Steps to Validate Article Creation Using API Log in to your application and create a new article. Publish the article. Perform an API call to retrieve the list of all articles. Use $.title with double dot notation to extract titles from the response. Store the titles in a variable, e.g., list of titles . Assert that the created article's title is included in the list of titles . Clean up by deleting the article using its slug ID . Validation Example To validate, you can use the assertion: check that stored value list of titles itself contains "Test title article" This process demonstrates how to effectively perform API testing and validation by leveraging JSON paths to extract necessary data and making assertions based on that data. In summary, when UI validation is not possible, API calls can be a robust alternative for confirming the integrity of test data.
Video Transcript
In this lesson, we're going to talk about one more use case of using the APIs in Test Trigger. So imagine you have a test application which does not have a UI for validation of particular test data or particular data after the test execution. So in this case, making API can be a good example of how you can perform the validation. And in this lesson, I will show you how to do that. So let's get into it. So in the previous lesson, we made this scenario, the test article creation. So we made the creation of the article. We published it here. And then we validated that this article is displayed on the edit article page and on the global feed page. And then we cleaned up using API. But imagine the situation that your application, let's say, doesn't have the edit article page or global feed page. All you have is just, let's say, publish the article and then message, for example, article published successfully, something like this. And you don't know for sure, was this article created or not? Does it exist in database or not? And in the situations like this, you can use API to perform this kind of validation. And let's simulate this situation. So I will copy this entire test and create a new test and we'll modify for our new use case. So validation using API. And I paste this over here. So this is login to your application, create new article. And then we don't have these two steps to validate on the UI. So our last step in the UI will be publish the article. So the next step, we need to perform API calls to validate that this article was created. And we can reuse this API call that we already used before to get the slug ID for the article. But instead, we will get the list of all articles inside of our application and validate that article that we just created in UI is created on the backend. So let me grab this example and I will modify it a little bit. So I need to put it right here after get access token. And it will be validate article creation. So now let's modify it a little bit. So it's gonna be get API call to the same endpoint with the same access token and then get. And instead of getting the slug ID, we need to get the list of the articles or let's say the list of the titles that are created and exist in the database. And the way how we can grab all the titles from the array is using this double dot notation and title. So what's gonna happen, here is our postman. So articles is the array of the objects. So it's object number one, object number two, and so on. And each article has a title. So when we put $.title, JSON path will find just the title keys inside of our object. And the result, we're gonna get array of title strings. So this object over here will give us just the array of all titles from the list of the titles. And we want to save this object as list of titles, something like this. And after we got this, we can perform a validation if the article that we have created is part of this list. And this is how we can do. We just create an assertion. Check that stored value list of titles. And then we use a keyword itself. Itself contains and the value that we have created over here. Test title article. Test title article. And yeah, I believe that's it. And after we perform this validation, we can clean up this article. So we repeat the steps that we had before. Get this log ID. And based on this log ID, delete the article. So let's quickly run this to make sure it is working. All right, as you can see, test pass successfully. And this is the step. Check that stored value itself contains, stored value contains this article. And this is a get call that return us this values and made a validation. So this works successfully. And let's quickly summarize what we did in this lesson. So if you want to validate a test data using API, you can perform API call. Then using a JSON path, you can retrieve the needed data from the JSON response and save this data into the object. And then you can make an assertion of this object using the construction stored value itself and then use either equal to or contains or something like this to perform the assertion. So this is how you can essentially do API testing and API validation. All right, that's it guys and see you in the next lesson.