Programatically skip configuration method in TestNG

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Programatically skip configuration method in TestNG

pmensik
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?

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Programatically skip configuration method in TestNG

⇜Krishnan Mahadevan⇝
Rather than throwing a SkipException which is bound to cause test methods to be skipped as well, why not just wrap the code that should be executed conditionally within an if block. 

If ( condition true) execute specific config
Else 
Don't do anything. 

Wouldn't that work ?

iSent. iPhone. iReget. iThumbs.iTypos!

On 11-Mar-2014, at 16:43, Petr Menšík <[hidden email]> wrote:

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?

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
Visit this group at http://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.