I'm using Citrus Framevork and have some pre-test steps to get auth-token and then use it in whole test plan. And don't clearly understand usage of TestContext in this case and how to access var. thru several testIT classes:
GetTokenIT.java:
http()
.client(HttpTqaClient)
.receive()
.response(HttpStatus.OK)
.messageType(MessageType.JSON)
.extractFromHeader("Authorization", "header_token")
.extractFromPayload("$.id_token", "payload_token");
action(new AbstractTestAction() {
@Override
public void doExecute(TestContext context) {
String token = context.getVariable("payload_token");
System.out.println("where is my token?" +token);
//Result: DEBUG port.LoggingReporter|where is my token?eyJhbGciOiJIUzUxMiJ9.
That part works fine only in GetTokenIT.class. How to pass/call variable token in nex test steps? GetClientIdIT.java:
public class GetClientIdIT extends TestNGCitrusTestDesigner {
@Autowired
private HttpClient HttpTqaClient;
@Test
@Parameters("context")
@CitrusTest(name = "GetClientId")
public void testGet(@Optional @CitrusResource TestContext context)
//HOW TO CALL VARIABLE "TOKEN" HERE?
System.out.println("where is my token?" +token);
http()
.client(HttpTqaClient)
.send()
.get("/account/api/lk/lk-client/current")
.accept("application/json")
.contentType("application/json")
.header("Authorization", "${token}");
http()
.client(HttpTqaClient)
.receive()
.response(HttpStatus.OK)
.messageType(MessageType.JSON);
Aucun commentaire:
Enregistrer un commentaire