Skip to content
Advertisement

How To Use Response value In Another Method

I am working on restassured and here is my 2 methods. I want to use the albumId returned from the AlbumList method in the other method

JavaScript

I know these are void and doesnt return anything but idk how to use it. Bye the these methods are in the same class. Thanks in advance

JavaScript

}

Advertisement

Answer

The easiest way is to change the return type of the AlbumList() method from void to String:

public String AlbumList() {

And in AlbumDetails() method we should change:

.when().get("/album/" + AlbumList())

Another option is to create instance variable albumId, not locally in AlbumList() method, and use it:

JavaScript

P.S. Here are some more tips:

  1. due to clean code more correct name describes what these methods do, e.g. getAlbumList() or storeAlbumList() and smth similar for another method;
  2. for extracting jsonPath from response we can use: JsonPath js = given()....extract().jsonPath();
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement