Skip TestCase at Runtime

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Skip TestCase at Runtime

Benjamin87
Hi,

I want to achieve the following szenario:

In the @BeforeSuite I want to define an Array with Testcases that should be skipped:

skipit = new ArrayList<String>();
skipit.add("Test1");

So if the TestSuite starts, all Testcases that should be skipped and therefore are defined in the skip array, should be set to "Enabled=false" in the Annotation. Also all Testcases, which depend on the skipped testcases should depend on the testcase before the skiped one.

Test0 <-- Test1 <-- Test2
Test0<--Test2 (Test1:enabled=false)

So I tried to write my own Annotation Transformer.

My Problem:

The Annotation Transformer is called BEFORE the @BeforeSuite-Lifecycle, so my skipped array is empty. Is there any way to call it after the @BeforeSuite?

In general can i modify Annotation after the @BeforeSuite?

If this it not possible(which would be very bad for me). How can i pass parameters from the .xml Testconfiguration-file, to achieve a skip-list, which will be noticed from the Annation Transformer?

Thanks for your reply!
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Skip TestCase at Runtime

Cédric Beust ♔-2
Annotation transformers are run before the annotations are read, by definition (it wouldn't make much sense otherwise).

Another approach would be to define an IMethodInterceptor and remove from that list the methods you don't want to run.

One last thing: "skipped" has a specific meaning in TestNG, you seem to mean "disabled" or "ignored" here.

-- 
Cédric




On Wed, May 23, 2012 at 4:50 AM, Benjamin87 <[hidden email]> wrote:

Hi,

I want to achieve the following szenario:

In the @BeforeSuite I want to define an Array with Testcases that should be
skipped:

skipit = new ArrayList<String>();
skipit.add("Test1");

So if the TestSuite starts, all Testcases that should be skipped and
therefore are defined in the skip array, should be set to "Enabled=false" in
the Annotation. Also all Testcases, which depend on the skipped testcases
should depend on the testcase before the skiped one.

Test0 <-- Test1 <-- Test2
Test0<--Test2 (Test1:enabled=false)

So I tried to write my own Annotation Transformer.

My Problem:

The Annotation Transformer is called BEFORE the @BeforeSuite-Lifecycle, so
my skipped array is empty. Is there any way to call it after the
@BeforeSuite?

In general can i modify Annotation after the @BeforeSuite?

If this it not possible(which would be very bad for me). How can i pass
parameters from the .xml Testconfiguration-file, to achieve a skip-list,
which will be noticed from the Annation Transformer?

Thanks for your reply!
--
View this message in context: http://old.nabble.com/Skip-TestCase-at-Runtime-tp33895104p33895104.html
Sent from the testng-users mailing list archive at Nabble.com.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Skip TestCase at Runtime

Benjamin87
Yeah, disabled is the right definition.

What would happen to the depend Methods, if i remove an Method A with the IMethodInterceptor and Method B depends on Method A. Method B would be skipped or throw an error, right?

In that Case the parameter variant would be the best way. But how can i pass Parameters from the .xml Configuration File to an Annotation Transformer Class to modify Annotation before the Suite starts?

The @parameters is a Annotation as well, so it would be read after the Annotation Transformer?

Cedric Beust wrote
Annotation transformers are run before the annotations are read, by
definition (it wouldn't make much sense otherwise).

Another approach would be to define an IMethodInterceptor and remove from
that list the methods you don't want to run.

One last thing: "skipped" has a specific meaning in TestNG, you seem to
mean "disabled" or "ignored" here.

--
Cédric




On Wed, May 23, 2012 at 4:50 AM, Benjamin87 <b.soeltenfuss@googlemail.com>wrote:

>
> Hi,
>
> I want to achieve the following szenario:
>
> In the @BeforeSuite I want to define an Array with Testcases that should be
> skipped:
>
> skipit = new ArrayList<String>();
> skipit.add("Test1");
>
> So if the TestSuite starts, all Testcases that should be skipped and
> therefore are defined in the skip array, should be set to "Enabled=false"
> in
> the Annotation. Also all Testcases, which depend on the skipped testcases
> should depend on the testcase before the skiped one.
>
> Test0 <-- Test1 <-- Test2
> Test0<--Test2 (Test1:enabled=false)
>
> So I tried to write my own Annotation Transformer.
>
> My Problem:
>
> The Annotation Transformer is called BEFORE the @BeforeSuite-Lifecycle, so
> my skipped array is empty. Is there any way to call it after the
> @BeforeSuite?
>
> In general can i modify Annotation after the @BeforeSuite?
>
> If this it not possible(which would be very bad for me). How can i pass
> parameters from the .xml Testconfiguration-file, to achieve a skip-list,
> which will be noticed from the Annation Transformer?
>
> Thanks for your reply!
> --
> View this message in context:
> http://old.nabble.com/Skip-TestCase-at-Runtime-tp33895104p33895104.html
> Sent from the testng-users mailing list archive at Nabble.com.
>
> --
> You received this message because you are subscribed to the Google Groups
> "testng-users" group.
> To post to this group, send email to testng-users@googlegroups.com.
> To unsubscribe from this group, send email to
> testng-users+unsubscribe@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/testng-users?hl=en.
>
>

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to testng-users@googlegroups.com.
To unsubscribe from this group, send email to testng-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Skip TestCase at Runtime

Benjamin87
In reply to this post by Cédric Beust ♔-2
So i was little short on time lately, but know i have tried the
MethodInterceptor approach:

public class TestNG_MethodInterceptor extends StartTests implements
IMethodInterceptor {

        private HashMap<String,String[]> removedmeths = new
HashMap<String,String[]>();

        @Override
        public List<IMethodInstance> intercept(List<IMethodInstance> arg0,
                        ITestContext arg1) {
                List<IMethodInstance> result = new ArrayList<IMethodInstance>();
                if(skipit != null && skipit.size()>=1)
                {
                        for(IMethodInstance mi:arg0)
                        {
                                String methodname = mi.getMethod().getMethodName();
                                String[] dependmeth =
build_clear_methodsname(mi.getMethod().getMethodsDependedUpon());
                                Boolean add = true;
                                for(String s:skipit)
                                {
                                        if(s.equals(methodname))
                                        {
                                                removedmeths.put(methodname, dependmeth);
                                                add = false;
                                        }
                                }
                                for(String s :dependmeth)
                                {
                                        if(removedmeths.containsKey(s))
                                        {
                                                /*
                                                 * Something like "mi.set_depend_on_Method(removedmeths.get(s));
                                                 * Setting the depend_on_Method of the actual test to the
depend_on_Methods of the removed test
                                                 */
                                        }
                                }
                                if(add)result.add(mi);
                        }

                }
                return result;
        }

        private String[] build_clear_methodsname(String[] input)
        {
                String[] methnames = new String[input.length];

                for(int i=0;i<input.length;i++)
                {
                        methnames[i] = input[i].split("\\.")[input[i].split("\
\.").length-1];
                }
                return methnames;
        }

}

My Problem is, that i dont know how to change the Annoation of an
Method inside of the MethodInterceptor. I want to change the
dependencies for a Method. How can i do this?

Thanks for your replies!


On 24 Mai, 10:18, Benjamin87 <[hidden email]> wrote:

> Yeah, disabled is the right definition.
>
> What would happen to the depend Methods, if i remove an Method A with the
> IMethodInterceptor and Method B depends on Method A. Method B would be
> skipped or throw an error, right?
>
> In that Case the parameter variant would be the best way. But how can i pass
> Parameters from the .xml Configuration File to an Annotation Transformer
> Class to modify Annotation before the Suite starts?
>
> The @parameters is a Annotation as well, so it would be read after the
> Annotation Transformer?
>
>
>
>
>
>
>
>
>
> Cedric Beust wrote:
>
> > Annotation transformers are run before the annotations are read, by
> > definition (it wouldn't make much sense otherwise).
>
> > Another approach would be to define an IMethodInterceptor and remove from
> > that list the methods you don't want to run.
>
> > One last thing: "skipped" has a specific meaning in TestNG, you seem to
> > mean "disabled" or "ignored" here.
>
> > --
> > Cédric
>
> > On Wed, May 23, 2012 at 4:50 AM, Benjamin87
> > <[hidden email]>wrote:
>
> >> Hi,
>
> >> I want to achieve the following szenario:
>
> >> In the @BeforeSuite I want to define an Array with Testcases that should
> >> be
> >> skipped:
>
> >> skipit = new ArrayList<String>();
> >> skipit.add("Test1");
>
> >> So if the TestSuite starts, all Testcases that should be skipped and
> >> therefore are defined in theskiparray, should be set to "Enabled=false"
> >> in
> >> the Annotation. Also all Testcases, which depend on the skipped testcases
> >> should depend on thetestcasebefore the skiped one.
>
> >> Test0 <-- Test1 <-- Test2
> >> Test0<--Test2 (Test1:enabled=false)
>
> >> So I tried to write my own Annotation Transformer.
>
> >> My Problem:
>
> >> The Annotation Transformer is called BEFORE the @BeforeSuite-Lifecycle,
> >> so
> >> my skipped array is empty. Is there any way to call it after the
> >> @BeforeSuite?
>
> >> In general can i modify Annotation after the @BeforeSuite?
>
> >> If this it not possible(which would be very bad for me). How can i pass
> >> parameters from the .xml Testconfiguration-file, to achieve askip-list,
> >> which will be noticed from the Annation Transformer?
>
> >> Thanks for your reply!
> >> --
> >> View this message in context:
> >>http://old.nabble.com/Skip-TestCase-at-Runtime-tp33895104p33895104.html
> >> Sent from the testng-users mailing list archive at Nabble.com.
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "testng-users" group.
> >> To post to this group, send email to [hidden email].
> >> To unsubscribe from this group, send email to
> >> [hidden email].
> >> For more options, visit this group at
> >>http://groups.google.com/group/testng-users?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "testng-users" group.
> > To post to this group, send email to [hidden email].
> > To unsubscribe from this group, send email to
> > [hidden email].
> > For more options, visit this group at
> >http://groups.google.com/group/testng-users?hl=en.
>
> --
> View this message in context:http://old.nabble.com/Skip-TestCase-at-Runtime-tp33895104p33900460.html
> Sent from the testng-users mailing list archive at Nabble.com.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Skip TestCase at Runtime

Cédric Beust ♔-2
You need to use an IAnnotationTransformer if you want to modify an annotation.

-- 
Cédric




On Fri, Jul 6, 2012 at 6:21 AM, Benjamin <[hidden email]> wrote:
So i was little short on time lately, but know i have tried the
MethodInterceptor approach:

public class TestNG_MethodInterceptor extends StartTests implements
IMethodInterceptor {

        private HashMap<String,String[]> removedmeths = new
HashMap<String,String[]>();

        @Override
        public List<IMethodInstance> intercept(List<IMethodInstance> arg0,
                        ITestContext arg1) {
                List<IMethodInstance> result = new ArrayList<IMethodInstance>();
                if(skipit != null && skipit.size()>=1)
                {
                        for(IMethodInstance mi:arg0)
                        {
                                String methodname = mi.getMethod().getMethodName();
                                String[] dependmeth =
build_clear_methodsname(mi.getMethod().getMethodsDependedUpon());
                                Boolean add = true;
                                for(String s:skipit)
                                {
                                        if(s.equals(methodname))
                                        {
                                                removedmeths.put(methodname, dependmeth);
                                                add = false;
                                        }
                                }
                                for(String s :dependmeth)
                                {
                                        if(removedmeths.containsKey(s))
                                        {
                                                /*
                                                 * Something like "mi.set_depend_on_Method(removedmeths.get(s));
                                                 * Setting the depend_on_Method of the actual test to the
depend_on_Methods of the removed test
                                                 */
                                        }
                                }
                                if(add)result.add(mi);
                        }

                }
                return result;
        }

        private String[] build_clear_methodsname(String[] input)
        {
                String[] methnames = new String[input.length];

                for(int i=0;i<input.length;i++)
                {
                        methnames[i] = input[i].split("\\.")[input[i].split("\
\.").length-1];
                }
                return methnames;
        }

}

My Problem is, that i dont know how to change the Annoation of an
Method inside of the MethodInterceptor. I want to change the
dependencies for a Method. How can i do this?

Thanks for your replies!


On 24 Mai, 10:18, Benjamin87 <[hidden email]> wrote:
> Yeah, disabled is the right definition.
>
> What would happen to the depend Methods, if i remove an Method A with the
> IMethodInterceptor and Method B depends on Method A. Method B would be
> skipped or throw an error, right?
>
> In that Case the parameter variant would be the best way. But how can i pass
> Parameters from the .xml Configuration File to an Annotation Transformer
> Class to modify Annotation before the Suite starts?
>
> The @parameters is a Annotation as well, so it would be read after the
> Annotation Transformer?
>
>
>
>
>
>
>
>
>
> Cedric Beust wrote:
>
> > Annotation transformers are run before the annotations are read, by
> > definition (it wouldn't make much sense otherwise).
>
> > Another approach would be to define an IMethodInterceptor and remove from
> > that list the methods you don't want to run.
>
> > One last thing: "skipped" has a specific meaning in TestNG, you seem to
> > mean "disabled" or "ignored" here.
>
> > --
> > Cédric
>
> > On Wed, May 23, 2012 at 4:50 AM, Benjamin87
> > <[hidden email]>wrote:
>
> >> Hi,
>
> >> I want to achieve the following szenario:
>
> >> In the @BeforeSuite I want to define an Array with Testcases that should
> >> be
> >> skipped:
>
> >> skipit = new ArrayList<String>();
> >> skipit.add("Test1");
>
> >> So if the TestSuite starts, all Testcases that should be skipped and
> >> therefore are defined in theskiparray, should be set to "Enabled=false"
> >> in
> >> the Annotation. Also all Testcases, which depend on the skipped testcases
> >> should depend on thetestcasebefore the skiped one.
>
> >> Test0 <-- Test1 <-- Test2
> >> Test0<--Test2 (Test1:enabled=false)
>
> >> So I tried to write my own Annotation Transformer.
>
> >> My Problem:
>
> >> The Annotation Transformer is called BEFORE the @BeforeSuite-Lifecycle,
> >> so
> >> my skipped array is empty. Is there any way to call it after the
> >> @BeforeSuite?
>
> >> In general can i modify Annotation after the @BeforeSuite?
>
> >> If this it not possible(which would be very bad for me). How can i pass
> >> parameters from the .xml Testconfiguration-file, to achieve askip-list,
> >> which will be noticed from the Annation Transformer?
>
> >> Thanks for your reply!
> >> --
> >> View this message in context:
> >>http://old.nabble.com/Skip-TestCase-at-Runtime-tp33895104p33895104.html
> >> Sent from the testng-users mailing list archive at Nabble.com.
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "testng-users" group.
> >> To post to this group, send email to [hidden email].
> >> To unsubscribe from this group, send email to
> >> [hidden email].
> >> For more options, visit this group at
> >>http://groups.google.com/group/testng-users?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "testng-users" group.
> > To post to this group, send email to [hidden email].
> > To unsubscribe from this group, send email to
> > [hidden email].
> > For more options, visit this group at
> >http://groups.google.com/group/testng-users?hl=en.
>
> --
> View this message in context:http://old.nabble.com/Skip-TestCase-at-Runtime-tp33895104p33900460.html
> Sent from the testng-users mailing list archive at Nabble.com.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Skip TestCase at Runtime

Sachin Francis
Hi Cédric,

I got a have a doubt here.

Is it possible to disable / skip tests based some analysis of data fed by Data Provider.

Say my Dataprovider injects data of type A, i want a subset test cases to be run. Say its type B i want another set of tests to be run.

I see that IAnnotationTransformer comes before the BeforeTest, hence i cant do any analysis of my data here.
IMethodInterceptor executes after BeforeTest but before BeforeClass, But BeforeTest executes only once though I run as factory. Hence even this is not helping me.

Is there anything else which i can try?

On Friday, 6 July 2012 20:56:23 UTC+5:30, Cédric Beust ♔ wrote:
You need to use an IAnnotationTransformer if you want to modify an annotation.

-- 
Cédric




On Fri, Jul 6, 2012 at 6:21 AM, Benjamin <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="vyw0aKNy_V4J" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">b.soel...@...> wrote:
So i was little short on time lately, but know i have tried the
MethodInterceptor approach:

public class TestNG_MethodInterceptor extends StartTests implements
IMethodInterceptor {

        private HashMap<String,String[]> removedmeths = new
HashMap<String,String[]>();

        @Override
        public List<IMethodInstance> intercept(List<IMethodInstance> arg0,
                        ITestContext arg1) {
                List<IMethodInstance> result = new ArrayList<IMethodInstance>();
                if(skipit != null && skipit.size()>=1)
                {
                        for(IMethodInstance mi:arg0)
                        {
                                String methodname = mi.getMethod().getMethodName();
                                String[] dependmeth =
build_clear_methodsname(mi.getMethod().getMethodsDependedUpon());
                                Boolean add = true;
                                for(String s:skipit)
                                {
                                        if(s.equals(methodname))
                                        {
                                                removedmeths.put(methodname, dependmeth);
                                                add = false;
                                        }
                                }
                                for(String s :dependmeth)
                                {
                                        if(removedmeths.containsKey(s))
                                        {
                                                /*
                                                 * Something like "mi.set_depend_on_Method(removedmeths.get(s));
                                                 * Setting the depend_on_Method of the actual test to the
depend_on_Methods of the removed test
                                                 */
                                        }
                                }
                                if(add)result.add(mi);
                        }

                }
                return result;
        }

        private String[] build_clear_methodsname(String[] input)
        {
                String[] methnames = new String[input.length];

                for(int i=0;i<input.length;i++)
                {
                        methnames[i] = input[i].split("\\.")[input[i].split("\
\.").length-1];
                }
                return methnames;
        }

}

My Problem is, that i dont know how to change the Annoation of an
Method inside of the MethodInterceptor. I want to change the
dependencies for a Method. How can i do this?

Thanks for your replies!


On 24 Mai, 10:18, Benjamin87 <[hidden email]> wrote:
> Yeah, disabled is the right definition.
>
> What would happen to the depend Methods, if i remove an Method A with the
> IMethodInterceptor and Method B depends on Method A. Method B would be
> skipped or throw an error, right?
>
> In that Case the parameter variant would be the best way. But how can i pass
> Parameters from the .xml Configuration File to an Annotation Transformer
> Class to modify Annotation before the Suite starts?
>
> The @parameters is a Annotation as well, so it would be read after the
> Annotation Transformer?
>
>
>
>
>
>
>
>
>
> Cedric Beust wrote:
>
> > Annotation transformers are run before the annotations are read, by
> > definition (it wouldn't make much sense otherwise).
>
> > Another approach would be to define an IMethodInterceptor and remove from
> > that list the methods you don't want to run.
>
> > One last thing: "skipped" has a specific meaning in TestNG, you seem to
> > mean "disabled" or "ignored" here.
>
> > --
> > Cédric
>
> > On Wed, May 23, 2012 at 4:50 AM, Benjamin87
> > <[hidden email]>wrote:
>
> >> Hi,
>
> >> I want to achieve the following szenario:
>
> >> In the @BeforeSuite I want to define an Array with Testcases that should
> >> be
> >> skipped:
>
> >> skipit = new ArrayList<String>();
> >> skipit.add("Test1");
>
> >> So if the TestSuite starts, all Testcases that should be skipped and
> >> therefore are defined in theskiparray, should be set to "Enabled=false"
> >> in
> >> the Annotation. Also all Testcases, which depend on the skipped testcases
> >> should depend on thetestcasebefore the skiped one.
>
> >> Test0 <-- Test1 <-- Test2
> >> Test0<--Test2 (Test1:enabled=false)
>
> >> So I tried to write my own Annotation Transformer.
>
> >> My Problem:
>
> >> The Annotation Transformer is called BEFORE the @BeforeSuite-Lifecycle,
> >> so
> >> my skipped array is empty. Is there any way to call it after the
> >> @BeforeSuite?
>
> >> In general can i modify Annotation after the @BeforeSuite?
>
> >> If this it not possible(which would be very bad for me). How can i pass
> >> parameters from the .xml Testconfiguration-file, to achieve askip-list,
> >> which will be noticed from the Annation Transformer?
>
> >> Thanks for your reply!
> >> --
> >> View this message in context:
> >><a href="http://old.nabble.com/Skip-TestCase-at-Runtime-tp33895104p33895104.html" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fold.nabble.com%2FSkip-TestCase-at-Runtime-tp33895104p33895104.html\46sa\75D\46sntz\0751\46usg\75AFQjCNGfqVT1qtXk6Cf0aNu3LXxcSdAM0A';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fold.nabble.com%2FSkip-TestCase-at-Runtime-tp33895104p33895104.html\46sa\75D\46sntz\0751\46usg\75AFQjCNGfqVT1qtXk6Cf0aNu3LXxcSdAM0A';return true;">http://old.nabble.com/Skip-TestCase-at-Runtime-tp33895104p33895104.html
> >> Sent from the testng-users mailing list archive at Nabble.com.
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "testng-users" group.
> >> To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="vyw0aKNy_V4J" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">testng...@....
> >> To unsubscribe from this group, send email to
> >> <a href="javascript:" target="_blank" gdf-obfuscated-mailto="vyw0aKNy_V4J" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">testng-users...@googlegroups.com.
> >> For more options, visit this group at
> >><a href="http://groups.google.com/group/testng-users?hl=en" target="_blank" onmousedown="this.href='http://groups.google.com/group/testng-users?hl\75en';return true;" onclick="this.href='http://groups.google.com/group/testng-users?hl\75en';return true;">http://groups.google.com/group/testng-users?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "testng-users" group.
> > To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="vyw0aKNy_V4J" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">testng...@....
> > To unsubscribe from this group, send email to
> > <a href="javascript:" target="_blank" gdf-obfuscated-mailto="vyw0aKNy_V4J" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">testng-users...@googlegroups.com.
> > For more options, visit this group at
> ><a href="http://groups.google.com/group/testng-users?hl=en" target="_blank" onmousedown="this.href='http://groups.google.com/group/testng-users?hl\75en';return true;" onclick="this.href='http://groups.google.com/group/testng-users?hl\75en';return true;">http://groups.google.com/group/testng-users?hl=en.
>
> --
> View this message in context:<a href="http://old.nabble.com/Skip-TestCase-at-Runtime-tp33895104p33900460.html" target="_blank" onmousedown="this.href='http://www.google.com/url?q\75http%3A%2F%2Fold.nabble.com%2FSkip-TestCase-at-Runtime-tp33895104p33900460.html\46sa\75D\46sntz\0751\46usg\75AFQjCNEtpLCrO5VmdSs4VlQdHgqFbAgIoQ';return true;" onclick="this.href='http://www.google.com/url?q\75http%3A%2F%2Fold.nabble.com%2FSkip-TestCase-at-Runtime-tp33895104p33900460.html\46sa\75D\46sntz\0751\46usg\75AFQjCNEtpLCrO5VmdSs4VlQdHgqFbAgIoQ';return true;">http://old.nabble.com/Skip-TestCase-at-Runtime-tp33895104p33900460.html
> Sent from the testng-users mailing list archive at Nabble.com.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="vyw0aKNy_V4J" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">testng...@....
To unsubscribe from this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="vyw0aKNy_V4J" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">testng-users...@googlegroups.com.
For more options, visit this group at <a href="http://groups.google.com/group/testng-users?hl=en" target="_blank" onmousedown="this.href='http://groups.google.com/group/testng-users?hl\75en';return true;" onclick="this.href='http://groups.google.com/group/testng-users?hl\75en';return true;">http://groups.google.com/group/testng-users?hl=en.


--
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
|  
Report Content as Inappropriate

Re: Skip TestCase at Runtime

sheetal singh

@Sachin Francis

Did you get a solution for your query, I am also trying something similar.

Based of data provider values I want to disable test rather skip it.



On Monday, 20 October 2014 10:38:27 UTC+5:30, Sachin Francis wrote:
Hi Cédric,

I got a have a doubt here.

Is it possible to disable / skip tests based some analysis of data fed by Data Provider.

Say my Dataprovider injects data of type A, i want a subset test cases to be run. Say its type B i want another set of tests to be run.

I see that IAnnotationTransformer comes before the BeforeTest, hence i cant do any analysis of my data here.
IMethodInterceptor executes after BeforeTest but before BeforeClass, But BeforeTest executes only once though I run as factory. Hence even this is not helping me.

Is there anything else which i can try?

On Friday, 6 July 2012 20:56:23 UTC+5:30, Cédric Beust ♔ wrote:
You need to use an IAnnotationTransformer if you want to modify an annotation.

-- 
Cédric




On Fri, Jul 6, 2012 at 6:21 AM, Benjamin <[hidden email]> wrote:
So i was little short on time lately, but know i have tried the
MethodInterceptor approach:

public class TestNG_MethodInterceptor extends StartTests implements
IMethodInterceptor {

        private HashMap<String,String[]> removedmeths = new
HashMap<String,String[]>();

        @Override
        public List<IMethodInstance> intercept(List<IMethodInstance> arg0,
                        ITestContext arg1) {
                List<IMethodInstance> result = new ArrayList<IMethodInstance>();
                if(skipit != null && skipit.size()>=1)
                {
                        for(IMethodInstance mi:arg0)
                        {
                                String methodname = mi.getMethod().getMethodName();
                                String[] dependmeth =
build_clear_methodsname(mi.getMethod().getMethodsDependedUpon());
                                Boolean add = true;
                                for(String s:skipit)
                                {
                                        if(s.equals(methodname))
                                        {
                                                removedmeths.put(methodname, dependmeth);
                                                add = false;
                                        }
                                }
                                for(String s :dependmeth)
                                {
                                        if(removedmeths.containsKey(s))
                                        {
                                                /*
                                                 * Something like "mi.set_depend_on_Method(removedmeths.get(s));
                                                 * Setting the depend_on_Method of the actual test to the
depend_on_Methods of the removed test
                                                 */
                                        }
                                }
                                if(add)result.add(mi);
                        }

                }
                return result;
        }

        private String[] build_clear_methodsname(String[] input)
        {
                String[] methnames = new String[input.length];

                for(int i=0;i<input.length;i++)
                {
                        methnames[i] = input[i].split("\\.")[input[i].split("\
\.").length-1];
                }
                return methnames;
        }

}

My Problem is, that i dont know how to change the Annoation of an
Method inside of the MethodInterceptor. I want to change the
dependencies for a Method. How can i do this?

Thanks for your replies!


On 24 Mai, 10:18, Benjamin87 <[hidden email]> wrote:
> Yeah, disabled is the right definition.
>
> What would happen to the depend Methods, if i remove an Method A with the
> IMethodInterceptor and Method B depends on Method A. Method B would be
> skipped or throw an error, right?
>
> In that Case the parameter variant would be the best way. But how can i pass
> Parameters from the .xml Configuration File to an Annotation Transformer
> Class to modify Annotation before the Suite starts?
>
> The @parameters is a Annotation as well, so it would be read after the
> Annotation Transformer?
>
>
>
>
>
>
>
>
>
> Cedric Beust wrote:
>
> > Annotation transformers are run before the annotations are read, by
> > definition (it wouldn't make much sense otherwise).
>
> > Another approach would be to define an IMethodInterceptor and remove from
> > that list the methods you don't want to run.
>
> > One last thing: "skipped" has a specific meaning in TestNG, you seem to
> > mean "disabled" or "ignored" here.
>
> > --
> > Cédric
>
> > On Wed, May 23, 2012 at 4:50 AM, Benjamin87
> > <[hidden email]>wrote:
>
> >> Hi,
>
> >> I want to achieve the following szenario:
>
> >> In the @BeforeSuite I want to define an Array with Testcases that should
> >> be
> >> skipped:
>
> >> skipit = new ArrayList<String>();
> >> skipit.add("Test1");
>
> >> So if the TestSuite starts, all Testcases that should be skipped and
> >> therefore are defined in theskiparray, should be set to "Enabled=false"
> >> in
> >> the Annotation. Also all Testcases, which depend on the skipped testcases
> >> should depend on thetestcasebefore the skiped one.
>
> >> Test0 <-- Test1 <-- Test2
> >> Test0<--Test2 (Test1:enabled=false)
>
> >> So I tried to write my own Annotation Transformer.
>
> >> My Problem:
>
> >> The Annotation Transformer is called BEFORE the @BeforeSuite-Lifecycle,
> >> so
> >> my skipped array is empty. Is there any way to call it after the
> >> @BeforeSuite?
>
> >> In general can i modify Annotation after the @BeforeSuite?
>
> >> If this it not possible(which would be very bad for me). How can i pass
> >> parameters from the .xml Testconfiguration-file, to achieve askip-list,
> >> which will be noticed from the Annation Transformer?
>
> >> Thanks for your reply!
> >> --
> >> View this message in context:
> >><a href="http://old.nabble.com/Skip-TestCase-at-Runtime-tp33895104p33895104.html" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fold.nabble.com%2FSkip-TestCase-at-Runtime-tp33895104p33895104.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGfqVT1qtXk6Cf0aNu3LXxcSdAM0A&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fold.nabble.com%2FSkip-TestCase-at-Runtime-tp33895104p33895104.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGfqVT1qtXk6Cf0aNu3LXxcSdAM0A&#39;;return true;">http://old.nabble.com/Skip-TestCase-at-Runtime-tp33895104p33895104.html
> >> Sent from the testng-users mailing list archive at Nabble.com.
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "testng-users" group.
> >> To post to this group, send email to [hidden email].
> >> To unsubscribe from this group, send email to
> >> testng-users...@googlegroups.com.
> >> For more options, visit this group at
> >><a href="http://groups.google.com/group/testng-users?hl=en" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://groups.google.com/group/testng-users?hl\x3den&#39;;return true;" onclick="this.href=&#39;http://groups.google.com/group/testng-users?hl\x3den&#39;;return true;">http://groups.google.com/group/testng-users?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "testng-users" group.
> > To post to this group, send email to [hidden email].
> > To unsubscribe from this group, send email to
> > testng-users...@googlegroups.com.
> > For more options, visit this group at
> ><a href="http://groups.google.com/group/testng-users?hl=en" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://groups.google.com/group/testng-users?hl\x3den&#39;;return true;" onclick="this.href=&#39;http://groups.google.com/group/testng-users?hl\x3den&#39;;return true;">http://groups.google.com/group/testng-users?hl=en.
>
> --
> View this message in context:<a href="http://old.nabble.com/Skip-TestCase-at-Runtime-tp33895104p33900460.html" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fold.nabble.com%2FSkip-TestCase-at-Runtime-tp33895104p33900460.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEtpLCrO5VmdSs4VlQdHgqFbAgIoQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fold.nabble.com%2FSkip-TestCase-at-Runtime-tp33895104p33900460.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEtpLCrO5VmdSs4VlQdHgqFbAgIoQ&#39;;return true;">http://old.nabble.com/Skip-TestCase-at-Runtime-tp33895104p33900460.html
> Sent from the testng-users mailing list archive at Nabble.com.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at <a href="http://groups.google.com/group/testng-users?hl=en" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://groups.google.com/group/testng-users?hl\x3den&#39;;return true;" onclick="this.href=&#39;http://groups.google.com/group/testng-users?hl\x3den&#39;;return true;">http://groups.google.com/group/testng-users?hl=en.


--
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 https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Skip TestCase at Runtime

Krishnan Mahadevan
Sheetal,


Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"
My Scribblings @ http://wakened-cognition.blogspot.com/
My Technical Scribbings @ http://rationaleemotions.wordpress.com/

On Wed, Mar 1, 2017 at 2:48 PM, sheetal singh <[hidden email]> wrote:

@Sachin Francis

Did you get a solution for your query, I am also trying something similar.

Based of data provider values I want to disable test rather skip it.



On Monday, 20 October 2014 10:38:27 UTC+5:30, Sachin Francis wrote:
Hi Cédric,

I got a have a doubt here.

Is it possible to disable / skip tests based some analysis of data fed by Data Provider.

Say my Dataprovider injects data of type A, i want a subset test cases to be run. Say its type B i want another set of tests to be run.

I see that IAnnotationTransformer comes before the BeforeTest, hence i cant do any analysis of my data here.
IMethodInterceptor executes after BeforeTest but before BeforeClass, But BeforeTest executes only once though I run as factory. Hence even this is not helping me.

Is there anything else which i can try?

On Friday, 6 July 2012 20:56:23 UTC+5:30, Cédric Beust ♔ wrote:
You need to use an IAnnotationTransformer if you want to modify an annotation.

-- 
Cédric




On Fri, Jul 6, 2012 at 6:21 AM, Benjamin <[hidden email]> wrote:
So i was little short on time lately, but know i have tried the
MethodInterceptor approach:

public class TestNG_MethodInterceptor extends StartTests implements
IMethodInterceptor {

        private HashMap<String,String[]> removedmeths = new
HashMap<String,String[]>();

        @Override
        public List<IMethodInstance> intercept(List<IMethodInstance> arg0,
                        ITestContext arg1) {
                List<IMethodInstance> result = new ArrayList<IMethodInstance>();
                if(skipit != null && skipit.size()>=1)
                {
                        for(IMethodInstance mi:arg0)
                        {
                                String methodname = mi.getMethod().getMethodName();
                                String[] dependmeth =
build_clear_methodsname(mi.getMethod().getMethodsDependedUpon());
                                Boolean add = true;
                                for(String s:skipit)
                                {
                                        if(s.equals(methodname))
                                        {
                                                removedmeths.put(methodname, dependmeth);
                                                add = false;
                                        }
                                }
                                for(String s :dependmeth)
                                {
                                        if(removedmeths.containsKey(s))
                                        {
                                                /*
                                                 * Something like "mi.set_depend_on_Method(removedmeths.get(s));
                                                 * Setting the depend_on_Method of the actual test to the
depend_on_Methods of the removed test
                                                 */
                                        }
                                }
                                if(add)result.add(mi);
                        }

                }
                return result;
        }

        private String[] build_clear_methodsname(String[] input)
        {
                String[] methnames = new String[input.length];

                for(int i=0;i<input.length;i++)
                {
                        methnames[i] = input[i].split("\\.")[input[i].split("\
\.").length-1];
                }
                return methnames;
        }

}

My Problem is, that i dont know how to change the Annoation of an
Method inside of the MethodInterceptor. I want to change the
dependencies for a Method. How can i do this?

Thanks for your replies!


On 24 Mai, 10:18, Benjamin87 <[hidden email]> wrote:
> Yeah, disabled is the right definition.
>
> What would happen to the depend Methods, if i remove an Method A with the
> IMethodInterceptor and Method B depends on Method A. Method B would be
> skipped or throw an error, right?
>
> In that Case the parameter variant would be the best way. But how can i pass
> Parameters from the .xml Configuration File to an Annotation Transformer
> Class to modify Annotation before the Suite starts?
>
> The @parameters is a Annotation as well, so it would be read after the
> Annotation Transformer?
>
>
>
>
>
>
>
>
>
> Cedric Beust wrote:
>
> > Annotation transformers are run before the annotations are read, by
> > definition (it wouldn't make much sense otherwise).
>
> > Another approach would be to define an IMethodInterceptor and remove from
> > that list the methods you don't want to run.
>
> > One last thing: "skipped" has a specific meaning in TestNG, you seem to
> > mean "disabled" or "ignored" here.
>
> > --
> > Cédric
>
> > On Wed, May 23, 2012 at 4:50 AM, Benjamin87
> > <[hidden email]>wrote:
>
> >> Hi,
>
> >> I want to achieve the following szenario:
>
> >> In the @BeforeSuite I want to define an Array with Testcases that should
> >> be
> >> skipped:
>
> >> skipit = new ArrayList<String>();
> >> skipit.add("Test1");
>
> >> So if the TestSuite starts, all Testcases that should be skipped and
> >> therefore are defined in theskiparray, should be set to "Enabled=false"
> >> in
> >> the Annotation. Also all Testcases, which depend on the skipped testcases
> >> should depend on thetestcasebefore the skiped one.
>
> >> Test0 <-- Test1 <-- Test2
> >> Test0<--Test2 (Test1:enabled=false)
>
> >> So I tried to write my own Annotation Transformer.
>
> >> My Problem:
>
> >> The Annotation Transformer is called BEFORE the @BeforeSuite-Lifecycle,
> >> so
> >> my skipped array is empty. Is there any way to call it after the
> >> @BeforeSuite?
>
> >> In general can i modify Annotation after the @BeforeSuite?
>
> >> If this it not possible(which would be very bad for me). How can i pass
> >> parameters from the .xml Testconfiguration-file, to achieve askip-list,
> >> which will be noticed from the Annation Transformer?
>
> >> Thanks for your reply!
> >> --
> >> View this message in context:
> >>http://old.nabble.com/Skip-TestCase-at-Runtime-tp33895104p33895104.html
> >> Sent from the testng-users mailing list archive at Nabble.com.
>
> >> --
> >> You received this message because you are subscribed to the Google Groups
> >> "testng-users" group.
> >> To post to this group, send email to [hidden email].
> >> To unsubscribe from this group, send email to
> >> [hidden email]om.
> >> For more options, visit this group at
> >>http://groups.google.com/group/testng-users?hl=en.
>
> > --
> > You received this message because you are subscribed to the Google Groups
> > "testng-users" group.
> > To post to this group, send email to [hidden email].
> > To unsubscribe from this group, send email to
> > [hidden email]om.
> > For more options, visit this group at
> >http://groups.google.com/group/testng-users?hl=en.
>
> --
> View this message in context:http://old.nabble.com/Skip-TestCase-at-Runtime-tp33895104p33900460.html
> Sent from the testng-users mailing list archive at Nabble.com.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email]om.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.


--
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 https://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 https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.
Loading...