Skip to content
Advertisement

How to save generated ID , and use it for deletion

I’m testing API , using rest assured , programming language is JAVA, so my issue is , I’m trying to get generated ID from the response body , using this ID, trying to delete created product, but I’m having issues to save generated ID , for more information I have the following Scenario

JavaScript

I have the following Step Definition

JavaScript

I have following ouput

JavaScript

so the problem is , I’m creating private static id; in a class level , and getting this id’s value from the reponse body using

JavaScript

as u can see in the scenario i’m creating two same products for validation, first product is being created successfully , second product is not created, because they have the same dates, and it’s working as expected , but i need to delete first created product, and get the Id of this first product , but JAVA is getting Id from the second product , which is not created, so the question is how do i save the Id from first product which is successfully created , and using this Id delete the product. I hope I have described the issue good enough , if not pls comment bellow , thanks in advance

Advertisement

Answer

One simple solution on the top of my head is that instead of using private static String id, you can use private static List<String> ids = new ArraysList<>();

You will save each id to list of ids

JavaScript

Then in the method that using it, you will get the id from ids

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement