In one class I get a code and an identifier in the method, and in another class I need to use them as input parameters. How to save the values of smsCode and smsId variables for use in another class?
import io.restassured.RestAssured; import io.restassured.specification.RequestSpecification; import io.restassured.response.Response; import io.restassured.response.ResponseBody; import io.restassured.path.json.JsonPath; import org.json.JSONObject; import org.testng.Assert; import org.testng.annotations.Test; class GetSmsTest { Config config = new Config (); String smsCode; String smsId; @Test void getSMSTest () { RequestSpecification request = RestAssured.given ().relaxedHTTPSValidation (); Response response = request.get (config.getToken); JsonPath jsonPath = response.jsonPath (); String token = jsonPath.get ("access_token"); request.header ("Authorization", "Bearer " + token); JSONObject jsonObject = new JSONObject (); jsonObject.put ("recipient", "9031111112"); request.header ("Content-Type", "application/json; charset=UTF-8"); request.body (jsonObject.toString ()); response = request.post (config.getSMS); jsonPath = response.jsonPath (); smsCode = jsonPath.get ("code"); smsId = jsonPath.get ("id"); } } package qa.onlinebroker; import io.restassured.RestAssured; import io.restassured.specification.RequestSpecification; import io.restassured.response.Response; import io.restassured.response.ResponseBody; import io.restassured.path.json.JsonPath; import org.json.JSONObject; import org.testng.Assert; import org.testng.annotations.Test; class CheckSmsTest { Config config = new Config (); GetSmsTest getSmsTest = new GetSmsTest (); @Test void checkSMSTest () { RequestSpecification request = RestAssured.given ().relaxedHTTPSValidation (); Response response = request.get (config.getToken); JsonPath jsonPath = response.jsonPath (); String token = jsonPath.get ("access_token"); request.header ("Authorization", "Bearer " + token); JSONObject jsonObject = new JSONObject (); jsonObject.put ("code", getSmsTest.smsCode); jsonObject.put ("id", getSmsTest.smsId); request.header ("Content-Type", "application/json; charset=UTF-8"); request.body (jsonObject.toString ()); response = request.post (config.checkSMS); } } import io.restassured.RestAssured; import io.restassured.path.json.*; import io.restassured.response.*; import io.restassured.specification.*; class Config { void setToken (String token) { this.accToken = token; RequestSpecification request = RestAssured.given ().relaxedHTTPSValidation (); Response response = request.get (getToken); JsonPath jsonPath = response.jsonPath (); String access_token = jsonPath.get ("access_token"); request.header ("Authorization", "Bearer " + accToken); } }