Re: [testng-dev] add test method execution using IMethodInterceptor listener. ... .

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

Re: [testng-dev] add test method execution using IMethodInterceptor listener. ... .

Michael Braiman
wWw X&*#
 .   . .  

On Wed, Mar 6, 2019, 2:53 AM Alexey Anischenko, <[hidden email]> wrote:
Hi Krishnan,

 I need a way to change order of execution for test methods (I have multiple test-methods per test-class), not the whole test-classes.

Here's the simple example, it works fine adding my methods in the order I specified (except the fact that listener is called twice with the same list of methods). Until I add dependencies.


The listener:
---------------------------------------------
import java.util.LinkedList;
import java.util.List;
import org.testng.IMethodInstance;
import org.testng.IMethodInterceptor;
import org.testng.ITestContext;

public class InterleaveExampleListener implements IMethodInterceptor {

@Override
public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context) {
List<IMethodInstance> retVal = new LinkedList<IMethodInstance>(methods);
retVal.add(methods.get(0));
retVal.add(methods.get(0));
retVal.add(methods.get(1));
retVal.add(methods.get(1));
retVal.add(methods.get(0));
retVal.add(methods.get(0));
retVal.add(methods.get(1));
return retVal;
}
}
-----------------------

The test:

-----------------------
import org.testng.Reporter;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

@Listeners({ InterleaveExampleListener.class })

public class InterleaveExample {

  @Test
  public void test0() {
  Reporter.log("this is test 0");
  }

//  @Test(dependsOnMethods = { "test0" }, enabled = true)
  @Test
  public void test1() {
  Reporter.log("this is test 1");
  }
  
//  @Test(dependsOnMethods = { "test1" }, enabled = true)
  @Test
  public void test2() {
  Reporter.log("this is test 2");
  }
}
----------------------

The above works fine. But, uncommenting test dependencies annotations ruins it all - listener is called once with full list of tests, then with test1 + test2, then with just test2, and does not execute the methods I add to the end of my returned list.

I need both the way to add my methods to the sequence, and the way to exactly specify the whole test method sequence. 
I will now play with removing all the dependencies from all my @Test annotations, and will then just create the proper orderfrom the scratch in method interceptor  listener. 

Other option is to rewrite my tests to be "one test-method per class" and then play with AlterSuiteListener.

WBR,
Alexey

On Wednesday, March 6, 2019 at 7:06:46 AM UTC+3, Krishnan Mahadevan wrote:

Alexey,

 

>>>> Creating a new list to return, and filling it with multiple copies of the corresponding IMethodInstance elements from the original list  - does not help. 

 

Why do you say so? Can you please help elaborate ?

 

The other option that you can use is to basically start duplicating XmlTest/XmlClass objects by implementing the IAlterSuiteListener, Would that help ?

 

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.com/

 

From: <[hidden email]> on behalf of Alexey Anischenko <[hidden email]>
Reply-To: <[hidden email]>
Date: Tuesday, March 5, 2019 at 7:46 PM
To: testng-dev <[hidden email]>
Subject: [testng-dev] add test method execution using IMethodInterceptor listener

 

Hi,

 

There are tons of examples on how to reorder, shuffle, delete some tests from the flow by implementing  IMethodInterceptor  and then adding this class as listener.

 

 

But, is there any way to ADD new test executions of THE SAME test method, in the specified order?

 

I mean, I have this interceptor method getting a list of: testmethod1, testmethod2.
I want for TestNG to execute the following sequence of test methods: testmethod1, testmethod2, testmethod2, testmethod1, testmethod1, testmethod2, testmethod1.

 

Creating a new list to return, and filling it with multiple copies of the corresponding IMethodInstance elements from the original list  - does not help. 

Need a way to create a NEW IMethodInstance elements specifying the test name. Is there any?

 

WBR,

Alexey

--
You received this message because you are subscribed to the Google Groups "testng-dev" 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-dev.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-dev" 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-dev.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-dev" 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-dev.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [testng-dev] add test method execution using IMethodInterceptor listener. ... .

Alexey Anischenko
 Michael, 
can you elaborate your point a little bit more? ;)

Speaking of me, I managed to make it work for spherical tests in vacuum (see my sample), except the fact that TestNG 6.14 and 7 crashes reporters at the end. 

For real ones (mine are using Webdriver, and I store the driver instance in a field), there are tons of other problems with TestNG  - it seems to continue calling @aftertest-annotated method somewhere in the middle of test flow,
and/or creating different class object instances for different calls of the same test method - thus losing the object fields. 
But I managed to make it work single-threaded by marking these @beforeTest and @afterTest methods as static members, and making the fields I use there as static too.



On Thursday, March 7, 2019 at 7:32:35 PM UTC+3, Michael Braiman wrote:
wWw X&*#
 .   . .  

On Wed, Mar 6, 2019, 2:53 AM Alexey Anischenko, <<a href="javascript:" rel="nofollow" target="_blank" gdf-obfuscated-mailto="q2O1G3e1BAAJ" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">avam0...@...> wrote:
Hi Krishnan,

 I need a way to change order of execution for test methods (I have multiple test-methods per test-class), not the whole test-classes.

Here's the simple example, it works fine adding my methods in the order I specified (except the fact that listener is called twice with the same list of methods). Until I add dependencies.


The listener:
---------------------------------------------
import java.util.LinkedList;
import java.util.List;
import org.testng.IMethodInstance;
import org.testng.IMethodInterceptor;
import org.testng.ITestContext;

public class InterleaveExampleListener implements IMethodInterceptor {

@Override
public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context) {
List<IMethodInstance> retVal = new LinkedList<IMethodInstance>(methods);
retVal.add(methods.get(0));
retVal.add(methods.get(0));
retVal.add(methods.get(1));
retVal.add(methods.get(1));
retVal.add(methods.get(0));
retVal.add(methods.get(0));
retVal.add(methods.get(1));
return retVal;
}
}
-----------------------

The test:

-----------------------
import org.testng.Reporter;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

@Listeners({ InterleaveExampleListener.class })

public class InterleaveExample {

  @Test
  public void test0() {
  Reporter.log("this is test 0");
  }

//  @Test(dependsOnMethods = { "test0" }, enabled = true)
  @Test
  public void test1() {
  Reporter.log("this is test 1");
  }
  
//  @Test(dependsOnMethods = { "test1" }, enabled = true)
  @Test
  public void test2() {
  Reporter.log("this is test 2");
  }
}
----------------------

The above works fine. But, uncommenting test dependencies annotations ruins it all - listener is called once with full list of tests, then with test1 + test2, then with just test2, and does not execute the methods I add to the end of my returned list.

I need both the way to add my methods to the sequence, and the way to exactly specify the whole test method sequence. 
I will now play with removing all the dependencies from all my @Test annotations, and will then just create the proper orderfrom the scratch in method interceptor  listener. 

Other option is to rewrite my tests to be "one test-method per class" and then play with AlterSuiteListener.

WBR,
Alexey

On Wednesday, March 6, 2019 at 7:06:46 AM UTC+3, Krishnan Mahadevan wrote:

Alexey,

 

>>>> Creating a new list to return, and filling it with multiple copies of the corresponding IMethodInstance elements from the original list  - does not help. 

 

Why do you say so? Can you please help elaborate ?

 

The other option that you can use is to basically start duplicating XmlTest/XmlClass objects by implementing the IAlterSuiteListener, Would that help ?

 

Thanks & Regards

Krishnan Mahadevan

 

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"

My Scribblings @ <a href="http://wakened-cognition.blogspot.com/" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Fwakened-cognition.blogspot.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNHzOdYJCASIDF_28vQtkp9gnKAYSQ&#39;;return true;">http://wakened-cognition.blogspot.com/

My Technical Scribbings @ <a href="http://rationaleemotions.com/" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEu6PReDiSuU6wKXYuoZw5UXHRtSA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEu6PReDiSuU6wKXYuoZw5UXHRtSA&#39;;return true;">http://rationaleemotions.com/

 

From: <[hidden email]> on behalf of Alexey Anischenko <[hidden email]>
Reply-To: <[hidden email]>
Date: Tuesday, March 5, 2019 at 7:46 PM
To: testng-dev <[hidden email]>
Subject: [testng-dev] add test method execution using IMethodInterceptor listener

 

Hi,

 

There are tons of examples on how to reorder, shuffle, delete some tests from the flow by implementing  IMethodInterceptor  and then adding this class as listener.

 

 

But, is there any way to ADD new test executions of THE SAME test method, in the specified order?

 

I mean, I have this interceptor method getting a list of: testmethod1, testmethod2.
I want for TestNG to execute the following sequence of test methods: testmethod1, testmethod2, testmethod2, testmethod1, testmethod1, testmethod2, testmethod1.

 

Creating a new list to return, and filling it with multiple copies of the corresponding IMethodInstance elements from the original list  - does not help. 

Need a way to create a NEW IMethodInstance elements specifying the test name. Is there any?

 

WBR,

Alexey

--
You received this message because you are subscribed to the Google Groups "testng-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-dev+...@googlegroups.com.
To post to this group, send email to [hidden email].
Visit this group at <a href="https://groups.google.com/group/testng-dev" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/group/testng-dev&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/testng-dev&#39;;return true;">https://groups.google.com/group/testng-dev.
For more options, visit <a href="https://groups.google.com/d/optout" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to <a href="javascript:" rel="nofollow" target="_blank" gdf-obfuscated-mailto="q2O1G3e1BAAJ" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng-dev+...@googlegroups.com.
To post to this group, send email to <a href="javascript:" rel="nofollow" target="_blank" gdf-obfuscated-mailto="q2O1G3e1BAAJ" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testn...@....
Visit this group at <a href="https://groups.google.com/group/testng-dev" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/group/testng-dev&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/testng-dev&#39;;return true;">https://groups.google.com/group/testng-dev.
For more options, visit <a href="https://groups.google.com/d/optout" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/optout&#39;;return true;">https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-dev" 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-dev.
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: [testng-dev] add test method execution using IMethodInterceptor listener. ... .

Michael Braiman
Sorry, my android phone typed this message in my pocket.

On Thu, Mar 7, 2019, 3:48 PM Alexey Anischenko, <[hidden email]> wrote:
 Michael, 
can you elaborate your point a little bit more? ;)

Speaking of me, I managed to make it work for spherical tests in vacuum (see my sample), except the fact that TestNG 6.14 and 7 crashes reporters at the end. 

For real ones (mine are using Webdriver, and I store the driver instance in a field), there are tons of other problems with TestNG  - it seems to continue calling @aftertest-annotated method somewhere in the middle of test flow,
and/or creating different class object instances for different calls of the same test method - thus losing the object fields. 
But I managed to make it work single-threaded by marking these @beforeTest and @afterTest methods as static members, and making the fields I use there as static too.



On Thursday, March 7, 2019 at 7:32:35 PM UTC+3, Michael Braiman wrote:
wWw X&*#
 .   . .  

On Wed, Mar 6, 2019, 2:53 AM Alexey Anischenko, <[hidden email]> wrote:
Hi Krishnan,

 I need a way to change order of execution for test methods (I have multiple test-methods per test-class), not the whole test-classes.

Here's the simple example, it works fine adding my methods in the order I specified (except the fact that listener is called twice with the same list of methods). Until I add dependencies.


The listener:
---------------------------------------------
import java.util.LinkedList;
import java.util.List;
import org.testng.IMethodInstance;
import org.testng.IMethodInterceptor;
import org.testng.ITestContext;

public class InterleaveExampleListener implements IMethodInterceptor {

@Override
public List<IMethodInstance> intercept(List<IMethodInstance> methods, ITestContext context) {
List<IMethodInstance> retVal = new LinkedList<IMethodInstance>(methods);
retVal.add(methods.get(0));
retVal.add(methods.get(0));
retVal.add(methods.get(1));
retVal.add(methods.get(1));
retVal.add(methods.get(0));
retVal.add(methods.get(0));
retVal.add(methods.get(1));
return retVal;
}
}
-----------------------

The test:

-----------------------
import org.testng.Reporter;
import org.testng.annotations.Listeners;
import org.testng.annotations.Test;

@Listeners({ InterleaveExampleListener.class })

public class InterleaveExample {

  @Test
  public void test0() {
  Reporter.log("this is test 0");
  }

//  @Test(dependsOnMethods = { "test0" }, enabled = true)
  @Test
  public void test1() {
  Reporter.log("this is test 1");
  }
  
//  @Test(dependsOnMethods = { "test1" }, enabled = true)
  @Test
  public void test2() {
  Reporter.log("this is test 2");
  }
}
----------------------

The above works fine. But, uncommenting test dependencies annotations ruins it all - listener is called once with full list of tests, then with test1 + test2, then with just test2, and does not execute the methods I add to the end of my returned list.

I need both the way to add my methods to the sequence, and the way to exactly specify the whole test method sequence. 
I will now play with removing all the dependencies from all my @Test annotations, and will then just create the proper orderfrom the scratch in method interceptor  listener. 

Other option is to rewrite my tests to be "one test-method per class" and then play with AlterSuiteListener.

WBR,
Alexey

On Wednesday, March 6, 2019 at 7:06:46 AM UTC+3, Krishnan Mahadevan wrote:

Alexey,

 

>>>> Creating a new list to return, and filling it with multiple copies of the corresponding IMethodInstance elements from the original list  - does not help. 

 

Why do you say so? Can you please help elaborate ?

 

The other option that you can use is to basically start duplicating XmlTest/XmlClass objects by implementing the IAlterSuiteListener, Would that help ?

 

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.com/

 

From: <[hidden email]> on behalf of Alexey Anischenko <[hidden email]>
Reply-To: <[hidden email]>
Date: Tuesday, March 5, 2019 at 7:46 PM
To: testng-dev <[hidden email]>
Subject: [testng-dev] add test method execution using IMethodInterceptor listener

 

Hi,

 

There are tons of examples on how to reorder, shuffle, delete some tests from the flow by implementing  IMethodInterceptor  and then adding this class as listener.

 

 

But, is there any way to ADD new test executions of THE SAME test method, in the specified order?

 

I mean, I have this interceptor method getting a list of: testmethod1, testmethod2.
I want for TestNG to execute the following sequence of test methods: testmethod1, testmethod2, testmethod2, testmethod1, testmethod1, testmethod2, testmethod1.

 

Creating a new list to return, and filling it with multiple copies of the corresponding IMethodInstance elements from the original list  - does not help. 

Need a way to create a NEW IMethodInstance elements specifying the test name. Is there any?

 

WBR,

Alexey

--
You received this message because you are subscribed to the Google Groups "testng-dev" 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-dev.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-dev" 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-dev.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-dev" 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-dev.
For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "testng-dev" 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-dev.
For more options, visit https://groups.google.com/d/optout.