@BeforeMethod(alwaysRun = true)
public void BeforeMethod(Method method, Object[] testData){
TmsLink tmsLink = method.getAnnotation(TmsLink.class);
Description description = method.getAnnotation(Description.class);
Test test = method.getAnnotation(Test.class);
changeAnnotationValue(tmsLink, "value", "<GET FROM testData>");
changeAnnotationValue(description, "value", "<GET FROM testData>");
changeAnnotationValue(test, "description", "<GET FROM testData>");
}
@SuppressWarnings("unchecked")
public static Object changeAnnotationValue(Annotation annotation, String key, Object newValue){
System.out.println("BEFORE annotation: " + annotation);
Object handler = Proxy.getInvocationHandler(annotation);
Field f;
try {
f = handler.getClass().getDeclaredField("memberValues");
} catch (NoSuchFieldException | SecurityException e) {
throw new IllegalStateException(e);
}
f.setAccessible(true);
Map<String, Object> memberValues;
try {
memberValues = (Map<String, Object>) f.get(handler);
} catch (IllegalArgumentException | IllegalAccessException e) {
throw new IllegalStateException(e);
}
Object oldValue = memberValues.get(key);
if (oldValue == null || oldValue.getClass() != newValue.getClass()) {
throw new IllegalArgumentException();
}
memberValues.put(key,newValue);
System.out.println("AFTER annotation: " + annotation);
return oldValue;
}
Мне удалось изменить Allure @Description
и @TmsLink
и TestNG @Test.description
, но Allure по-прежнему получает TestNG @Test.description
до его изменения, поэтому мне все еще нужно обновить @ Test.description, прежде чем Allure перехватит его .