Quantcast

[testng-dev] Add a listener that hooks around BeforeMethod & AfterMethod fixtures

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

[testng-dev] Add a listener that hooks around BeforeMethod & AfterMethod fixtures

Dmitry Baev
Allure 2 has support of test fixtures, so we need to catch all the steps and attachments from all the fixtures. It is pretty much possible except method-level fixtures. Now I am using `IInvokedMethodListener2` to catch steps in fixture, but I can't get the test method it is running for. 

So it would be nice to have a new listener around all method-level fixtures. 

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

[testng-dev] Re: Add a listener that hooks around BeforeMethod & AfterMethod fixtures

Julien Herr
Before/AfterMethods are running for all test methods of the class.
You should be able to catch all methods of the class with a BeforeClass: http://testng.org/javadocs/org/testng/IClassListener.html

Let me know if it is working or not.

Le mercredi 7 décembre 2016 16:53:10 UTC+1, Dmitry Baev a écrit :
Allure 2 has support of test fixtures, so we need to catch all the steps and attachments from all the fixtures. It is pretty much possible except method-level fixtures. Now I am using `IInvokedMethodListener2` to catch steps in fixture, but I can't get the test method it is running for. 

So it would be nice to have a new listener around all method-level fixtures. 

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

[testng-dev] Re: Add a listener that hooks around BeforeMethod & AfterMethod fixtures

Dmitry Baev
Yeah, I can get all of the test methods for BeforeMethod, but I can't get the current one: I mean 

-testClass started

-methodBefore "setUp" started
-methodBefore "setUp" finished
-testMethod "A" started
-testMethod "A" finished
-methodAfter "tearDown" started
-methodAfter "tearDown" finished

-methodBefore "setUp" started
-methodBefore "setUp" finished
-testMethod "B" started
-testMethod "B" finished
-methodAfter "tearDown" started
-methodAfter "tearDown" finished

-testClass finished

I can get that "setUp" and "tearDown" running for both methods "A" and "B". But I need to catch artefacts (steps, attachments, logs etc) collected during each setUp/tearDown execution to right test case. So I create threadLocal storage on fixture start that collects all the artefacts, and then I need to add that storage to related method on fixture finish. The problem is that I can't find is that fixture just run for test case "A" or "B". 

With the hooks that I propose to add this situation will looks like this:

-testCase A started (that is the point when Allure Test Case with name "A" is created )
-methodBefore "setUp" started (start new test fixture named "stepUp")
-methodBefore "setUp" finished (stop current fixture and add it to current test case)
-testMethod "A" started (start test case body)
-testMethod "A" finished  (stop test case body and add it to current test case)
-methodAfter "tearDown" started ...
-methodAfter "tearDown" finished ...
-testCase A finished (stop current test case and add store it to results folder as json)

On Wednesday, December 7, 2016 at 7:27:58 PM UTC+3, Julien Herr wrote:
Before/AfterMethods are running for all test methods of the class.
You should be able to catch all methods of the class with a BeforeClass: <a href="http://testng.org/javadocs/org/testng/IClassListener.html" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ftestng.org%2Fjavadocs%2Forg%2Ftestng%2FIClassListener.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFa04Y5n7HzJ8nUwZo8h51x2X_g2w&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ftestng.org%2Fjavadocs%2Forg%2Ftestng%2FIClassListener.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFa04Y5n7HzJ8nUwZo8h51x2X_g2w&#39;;return true;">http://testng.org/javadocs/org/testng/IClassListener.html

Let me know if it is working or not.

Le mercredi 7 décembre 2016 16:53:10 UTC+1, Dmitry Baev a écrit :
Allure 2 has support of test fixtures, so we need to catch all the steps and attachments from all the fixtures. It is pretty much possible except method-level fixtures. Now I am using `IInvokedMethodListener2` to catch steps in fixture, but I can't get the test method it is running for. 

So it would be nice to have a new listener around all method-level fixtures. 

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

[testng-dev] Re: Add a listener that hooks around BeforeMethod & AfterMethod fixtures

Julien Herr
Could you describe a bit more what you need? What exactly will the new listener look like?

But I think it is possible to find an alternative with the current listeners.

-methodBefore "setUp" started (start new test fixture named "stepUp" on Allure Test Case called "?")
-methodBefore "setUp" finished (stop current fixture and add it to current test case)
-testMethod "A" started (start test case body and update the Allure Test Case name/create it if it doesn't exist)
-testMethod "A" finished (stop test case body and add it to current test case)
-methodAfter "tearDown" started ...
-methodAfter "tearDown" finished (testCase A finished)...

For sure, it is not the smarter way but it should work.

Le mercredi 7 décembre 2016 17:59:02 UTC+1, Dmitry Baev a écrit :
Yeah, I can get all of the test methods for BeforeMethod, but I can't get the current one: I mean 

-testClass started

-methodBefore "setUp" started
-methodBefore "setUp" finished
-testMethod "A" started
-testMethod "A" finished
-methodAfter "tearDown" started
-methodAfter "tearDown" finished

-methodBefore "setUp" started
-methodBefore "setUp" finished
-testMethod "B" started
-testMethod "B" finished
-methodAfter "tearDown" started
-methodAfter "tearDown" finished

-testClass finished

I can get that "setUp" and "tearDown" running for both methods "A" and "B". But I need to catch artefacts (steps, attachments, logs etc) collected during each setUp/tearDown execution to right test case. So I create threadLocal storage on fixture start that collects all the artefacts, and then I need to add that storage to related method on fixture finish. The problem is that I can't find is that fixture just run for test case "A" or "B". 

With the hooks that I propose to add this situation will looks like this:

-testCase A started (that is the point when Allure Test Case with name "A" is created )
-methodBefore "setUp" started (start new test fixture named "stepUp")
-methodBefore "setUp" finished (stop current fixture and add it to current test case)
-testMethod "A" started (start test case body)
-testMethod "A" finished  (stop test case body and add it to current test case)
-methodAfter "tearDown" started ...
-methodAfter "tearDown" finished ...
-testCase A finished (stop current test case and add store it to results folder as json)

On Wednesday, December 7, 2016 at 7:27:58 PM UTC+3, Julien Herr wrote:
Before/AfterMethods are running for all test methods of the class.
You should be able to catch all methods of the class with a BeforeClass: <a href="http://testng.org/javadocs/org/testng/IClassListener.html" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ftestng.org%2Fjavadocs%2Forg%2Ftestng%2FIClassListener.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFa04Y5n7HzJ8nUwZo8h51x2X_g2w&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ftestng.org%2Fjavadocs%2Forg%2Ftestng%2FIClassListener.html\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFa04Y5n7HzJ8nUwZo8h51x2X_g2w&#39;;return true;">http://testng.org/javadocs/org/testng/IClassListener.html

Let me know if it is working or not.

Le mercredi 7 décembre 2016 16:53:10 UTC+1, Dmitry Baev a écrit :
Allure 2 has support of test fixtures, so we need to catch all the steps and attachments from all the fixtures. It is pretty much possible except method-level fixtures. Now I am using `IInvokedMethodListener2` to catch steps in fixture, but I can't get the test method it is running for. 

So it would be nice to have a new listener around all method-level fixtures. 

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

[testng-dev] Re: Add a listener that hooks around BeforeMethod & AfterMethod fixtures

Scott Babcock
In reply to this post by Dmitry Baev
This is easily done via dependency injection. From the TestNG documentation:

  • Any @BeforeMethod (and @AfterMethod) can declare a parameter of type java.lang.reflect.Method. This parameter will receive the test method that will be called once this @BeforeMethod finishes (or after the method as run for @AfterMethod).

On Wednesday, December 7, 2016 at 7:53:10 AM UTC-8, Dmitry Baev wrote:
Allure 2 has support of test fixtures, so we need to catch all the steps and attachments from all the fixtures. It is pretty much possible except method-level fixtures. Now I am using `IInvokedMethodListener2` to catch steps in fixture, but I can't get the test method it is running for. 

So it would be nice to have a new listener around all method-level fixtures. 

--
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.
Loading...