【问题标题】:How to read step method contents from allure listener如何从 allure listener 读取 step 方法内容
【发布时间】:2021-08-28 22:53:41
【问题描述】:

目前,我正在使用 allure StepLifecycleListener 来收听@step。我想在方法中获取一些参数。

例如:我想得到 下面的“RequestIdentifier.userservice_CreateLogin”参数

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

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

我可以从 StepResult getparameters() 方法中获取 String deviceId、String authId、String otp,但是如何在 performUserLogin() 方法中获取一些参数。

【问题讨论】:

    标签: listener allure step


    【解决方案1】:

    你不能。 Step 注释适用于方法的签名,而不是它的主体。如果你想得到RequestIdentifier.userservice_CreateLogin的值,只需重载该方法并传递一个对应的值作为参数即可。

    另一方面,它似乎是一个public static 变量。在这种情况下,您始终可以从您的AllureStepListener 中显式访问它。但是,这将是一种丑陋的方法。

    我会考虑重新设计您的 API,使其与自定义类型(又名实体)一起使用,而不是传递原始字符串。在这种情况下,您始终可以将所有必需的数据(包括静态数据)组合到您的自定义实体中,然后通过 "Bla-bla {entity.field}" 语法在 Step 注释中轻松访问它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-09
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多