How to read step method contents from allure listener

Viewed 109

Currently, I am using allure StepLifecycleListener to listen to @step. I want to get some parameters inside the method.

For Eg : I want to get "RequestIdentifier.userservice_CreateLogin" parameter in below

@Step("Perform user login with retrieved OTP")
public BaseResponseDTO performUserLogin(String deviceId, String authId, String otp) {

 response = serviceManager.sendRequest(RequestIdentifier.userservice_CreateLogin, requestParams);
}

I can get String deviceId, String authId, String otp from StepResult getparameters() method, but how can I get some parameters inside the performUserLogin() method.

1 Answers

You can't. Step annotation works with the method's signature, not with its body. If you want to get RequestIdentifier.userservice_CreateLogin value, just overload the method and pass a corresponding value as an argument.

On the other hand, it seems like a public static variable. In this case, you can always explicitly access it from within your AllureStepListener. However, it'd be an ugly approach.

I'd consider redesigning your API the way it'll work with custom types (aka entities) rather than passing raw strings. In this case, you can always compose all the required data (including statics) into your custom entity and then easily access it within Step annotation via "Bla-bla {entity.field}" syntax.

Related