1 package vid.automation.test.infra;
3 import java.lang.reflect.Constructor;
4 import java.lang.reflect.Method;
5 import java.time.LocalDate;
6 import org.testng.IAnnotationTransformer;
7 import org.testng.annotations.ITestAnnotation;
10 TestNg listener that skip tests that are annotated with SkipTestUntil annotation
11 Pay attention that this listener shall be configured in the testng.xml (or command line)
13 public class SkipTestUntilTestngTransformer implements IAnnotationTransformer {
16 public void transform(ITestAnnotation annotation, Class testClass, Constructor testConstructor, Method testMethod) {
18 if (testMethod!=null) {
21 if (!annotation.getEnabled()) {
25 if (!testMethod.isAnnotationPresent(SkipTestUntil.class)) {
29 String dateAsStr = testMethod.getAnnotation(SkipTestUntil.class).value();
30 if (shallDisableTest(dateAsStr)) {
31 disableTest(annotation, testMethod.getDeclaringClass().getName(), dateAsStr);
34 } catch (Exception e) {
40 private boolean shallDisableTest(String dateAsStr) {
42 return LocalDate.now().isBefore(LocalDate.parse(dateAsStr));
44 catch (RuntimeException exception) {
45 System.out.println("Failure during processing of SkipTestUntil annotation value is " + dateAsStr);
46 exception.printStackTrace();
51 private void disableTest(ITestAnnotation annotation, String name, String dateAsStr) {
52 System.out.println("Ignore "+ name+" till "+dateAsStr);
53 annotation.setEnabled(false);