Programatically skip configuration method in TestNG

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Programatically skip configuration method in TestNG

pmensik
This post has NOT been accepted by the mailing list yet.
Hi, I have a (hopefully) easy question - is there a way how to skip configuration method in a listener?I have a code like this

public class SkipLoginMethodListener implements IInvokedMethodListener {

    private static final String SKIP_GROUP = "loginMethod";

    @Override
    public void beforeInvocation(IInvokedMethod invokedMethod, ITestResult testResult) {
        ITestNGMethod method = invokedMethod.getTestMethod();
        if (method.isAfterMethodConfiguration() || method.isBeforeMethodConfiguration()) {
            for (String group : method.getGroups()) {
                if (group.equals(SKIP_GROUP)) {
                    System.out.println("skipped " + method.getMethodName());
                    throw new SkipException("Configuration of the method " + method.getMethodName() + " skipped");
                }
            }
        }
    }
}

So, this is currently working, however it will also skip all the tests which are supposed to be executed after the @BeforeMethod(groups = {"loginMethod"}) - I need to skip only the configuration method. So is there a better way how to achieve what I want?