Need suggestion how to add more fields/paramters/methods to @Test annotations

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

Need suggestion how to add more fields/paramters/methods to @Test annotations

Rejish R
Hi, 

I have a situation where I would like to make  some existing fields mandatory and add more fields while creating a test using @Test.

I would like to mandate @Test annotation at class level to always have testName, description and add new field such as ticket. Also, I would like to mandate @Test at method level to always have some groups. Finally this should be visible in the sure-fire report , on running it as mvn test.

@Test(testName = "SearchTest" , description ="testing search", ticket="OSQ100")
public class OSQ100_SearchTest {
  
    @Test(groups = {Groups.SMOKE_TEST}, description ="testing data")
    public void validateTitle1Test() {
        RequestSpecification requestSpecification = new RestAssuredConfiguration().getRequestSpecification();
        requestSpecification.queryParam("at", "40.71455,-74.00714").queryParam("q", "hotels").queryParam("app_id", EndPoint.APP_ID_PREMIUM).queryParam("app_code", EndPoint.APP_CODE_PREMIUM).log().all();

        ValidatableResponse validatableResponse = given().spec(requestSpecification).get(EndPoint.DISCOVER_SEARCH_QUERY_PARAM).then();
        validatableResponse.assertThat().body("results.items", hasSize(greaterThan(20)));

       /* String json = given().spec(requestSpecification).get(EndPoint.DISCOVER_SEARCH_QUERY_PARAM).then().extract().asString();
        JsonPath jsonPath = new JsonPath(json).setRoot("results.items");
        System.out.println(jsonPath.get);*/
    }
  }

Thanks in advance!

Rejish

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

Re: Need suggestion how to add more fields/paramters/methods to @Test annotations

Krishnan Mahadevan
Why not build your own annotations which you parse via a listener such as IInvokedMethodListener and if there are any anomalies then abort ? 

Would that not work for you ?

Updating a TestNG annotation is not possible without TestNG being refactored. 

On Wed, Mar 7, 2018, 13:49 Rejish R <[hidden email]> wrote:
Hi, 

I have a situation where I would like to make  some existing fields mandatory and add more fields while creating a test using @Test.

I would like to mandate @Test annotation at class level to always have testName, description and add new field such as ticket. Also, I would like to mandate @Test at method level to always have some groups. Finally this should be visible in the sure-fire report , on running it as mvn test.

@Test(testName = "SearchTest" , description ="testing search", ticket="OSQ100")
public class OSQ100_SearchTest {
  
    @Test(groups = {Groups.SMOKE_TEST}, description ="testing data")
    public void validateTitle1Test() {
        RequestSpecification requestSpecification = new RestAssuredConfiguration().getRequestSpecification();
        requestSpecification.queryParam("at", "40.71455,-74.00714").queryParam("q", "hotels").queryParam("app_id", EndPoint.APP_ID_PREMIUM).queryParam("app_code", EndPoint.APP_CODE_PREMIUM).log().all();

        ValidatableResponse validatableResponse = given().spec(requestSpecification).get(EndPoint.DISCOVER_SEARCH_QUERY_PARAM).then();
        validatableResponse.assertThat().body("results.items", hasSize(greaterThan(20)));

       /* String json = given().spec(requestSpecification).get(EndPoint.DISCOVER_SEARCH_QUERY_PARAM).then().extract().asString();
        JsonPath jsonPath = new JsonPath(json).setRoot("results.items");
        System.out.println(jsonPath.get);*/
    }
  }

Thanks in advance!

Rejish

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

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/

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

Re: Need suggestion how to add more fields/paramters/methods to @Test annotations

Rejish R
Thanks for your reply Krishnan.

Yes, we also kind of reached the same solution of creating a new annotations.

Two solutions from here:
1) create a new annotation @TestParams and get the additional data in it along with @Test. (In this case we, have to add two annotations each time)-- This we have achieved. 
2) create a new annotation @CustomTest which will help us in getting the characteristics of @Test and @TestParam (In this case, we just have to run @CustomTest instead of @Test)  -- can you please guide us how can this be achieved.

- Rejish

On Wednesday, March 7, 2018 at 1:58:21 PM UTC+5:30, Krishnan Mahadevan wrote:
Why not build your own annotations which you parse via a listener such as IInvokedMethodListener and if there are any anomalies then abort ? 

Would that not work for you ?

Updating a TestNG annotation is not possible without TestNG being refactored. 

On Wed, Mar 7, 2018, 13:49 Rejish R <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="_1aEbsfAAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">rejis...@...> wrote:
Hi, 

I have a situation where I would like to make  some existing fields mandatory and add more fields while creating a test using @Test.

I would like to mandate @Test annotation at class level to always have testName, description and add new field such as ticket. Also, I would like to mandate @Test at method level to always have some groups. Finally this should be visible in the sure-fire report , on running it as mvn test.

@Test(testName = "SearchTest" , description ="testing search", ticket="OSQ100")
public class OSQ100_SearchTest {
  
    @Test(groups = {Groups.SMOKE_TEST}, description ="testing data")
    public void validateTitle1Test() {
        RequestSpecification requestSpecification = new RestAssuredConfiguration().getRequestSpecification();
        requestSpecification.queryParam("at", "40.71455,-74.00714").queryParam("q", "hotels").queryParam("app_id", EndPoint.APP_ID_PREMIUM).queryParam("app_code", EndPoint.APP_CODE_PREMIUM).log().all();

        ValidatableResponse validatableResponse = given().spec(requestSpecification).get(EndPoint.DISCOVER_SEARCH_QUERY_PARAM).then();
        validatableResponse.assertThat().body("results.items", hasSize(greaterThan(20)));

       /* String json = given().spec(requestSpecification).get(EndPoint.DISCOVER_SEARCH_QUERY_PARAM).then().extract().asString();
        JsonPath jsonPath = new JsonPath(json).setRoot("results.items");
        System.out.println(jsonPath.get);*/
    }
  }

Thanks in advance!

Rejish

--
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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="_1aEbsfAAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng-users...@googlegroups.com.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="_1aEbsfAAwAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">testng...@....
Visit this group at <a href="https://groups.google.com/group/testng-users" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/group/testng-users&#39;;return true;">https://groups.google.com/group/testng-users.
For more options, visit <a href="https://groups.google.com/d/optout" target="_blank" rel="nofollow" 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.
--

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/" target="_blank" rel="nofollow" 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.wordpress.com/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Frationaleemotions.wordpress.com%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNEcBOKyRn0lpL8LDbBuyAlKdwgXwQ&#39;;return true;">http://rationaleemotions.wordpress.com/

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

Re: Need suggestion how to add more fields/paramters/methods to @Test annotations

Krishnan Mahadevan
For your second option you may have to resort to peveraging a byte code manipulation library such as JavaAssist which looks for your @CustomTest and then injects @Test annotation in runtime. 

Please take a look at my blog post for more information. 

https://rationaleemotions.wordpress.com/2016/02/17/running-tests-which-dont-have-testng-annotations/ 

On Wed, Mar 7, 2018, 14:49 Rejish R <[hidden email]> wrote:
Thanks for your reply Krishnan.

Yes, we also kind of reached the same solution of creating a new annotations.

Two solutions from here:
1) create a new annotation @TestParams and get the additional data in it along with @Test. (In this case we, have to add two annotations each time)-- This we have achieved. 
2) create a new annotation @CustomTest which will help us in getting the characteristics of @Test and @TestParam (In this case, we just have to run @CustomTest instead of @Test)  -- can you please guide us how can this be achieved.

- Rejish

On Wednesday, March 7, 2018 at 1:58:21 PM UTC+5:30, Krishnan Mahadevan wrote:
Why not build your own annotations which you parse via a listener such as IInvokedMethodListener and if there are any anomalies then abort ? 

Would that not work for you ?

Updating a TestNG annotation is not possible without TestNG being refactored. 

On Wed, Mar 7, 2018, 13:49 Rejish R <[hidden email]> wrote:
Hi, 

I have a situation where I would like to make  some existing fields mandatory and add more fields while creating a test using @Test.

I would like to mandate @Test annotation at class level to always have testName, description and add new field such as ticket. Also, I would like to mandate @Test at method level to always have some groups. Finally this should be visible in the sure-fire report , on running it as mvn test.

@Test(testName = "SearchTest" , description ="testing search", ticket="OSQ100")
public class OSQ100_SearchTest {
  
    @Test(groups = {Groups.SMOKE_TEST}, description ="testing data")
    public void validateTitle1Test() {
        RequestSpecification requestSpecification = new RestAssuredConfiguration().getRequestSpecification();
        requestSpecification.queryParam("at", "40.71455,-74.00714").queryParam("q", "hotels").queryParam("app_id", EndPoint.APP_ID_PREMIUM).queryParam("app_code", EndPoint.APP_CODE_PREMIUM).log().all();

        ValidatableResponse validatableResponse = given().spec(requestSpecification).get(EndPoint.DISCOVER_SEARCH_QUERY_PARAM).then();
        validatableResponse.assertThat().body("results.items", hasSize(greaterThan(20)));

       /* String json = given().spec(requestSpecification).get(EndPoint.DISCOVER_SEARCH_QUERY_PARAM).then().extract().asString();
        JsonPath jsonPath = new JsonPath(json).setRoot("results.items");
        System.out.println(jsonPath.get);*/
    }
  }

Thanks in advance!

Rejish

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

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/

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

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/

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

Re: Need suggestion how to add more fields/paramters/methods to @Test annotations

Rejish R
Thanks, let me have a look

On Wed, Mar 7, 2018 at 2:59 PM, ⇜Krishnan Mahadevan⇝ <[hidden email]> wrote:
For your second option you may have to resort to peveraging a byte code manipulation library such as JavaAssist which looks for your @CustomTest and then injects @Test annotation in runtime. 

Please take a look at my blog post for more information. 

https://rationaleemotions.wordpress.com/2016/02/17/running-tests-which-dont-have-testng-annotations/ 

On Wed, Mar 7, 2018, 14:49 Rejish R <[hidden email]> wrote:
Thanks for your reply Krishnan.

Yes, we also kind of reached the same solution of creating a new annotations.

Two solutions from here:
1) create a new annotation @TestParams and get the additional data in it along with @Test. (In this case we, have to add two annotations each time)-- This we have achieved. 
2) create a new annotation @CustomTest which will help us in getting the characteristics of @Test and @TestParam (In this case, we just have to run @CustomTest instead of @Test)  -- can you please guide us how can this be achieved.

- Rejish

On Wednesday, March 7, 2018 at 1:58:21 PM UTC+5:30, Krishnan Mahadevan wrote:
Why not build your own annotations which you parse via a listener such as IInvokedMethodListener and if there are any anomalies then abort ? 

Would that not work for you ?

Updating a TestNG annotation is not possible without TestNG being refactored. 

On Wed, Mar 7, 2018, 13:49 Rejish R <[hidden email]> wrote:
Hi, 

I have a situation where I would like to make  some existing fields mandatory and add more fields while creating a test using @Test.

I would like to mandate @Test annotation at class level to always have testName, description and add new field such as ticket. Also, I would like to mandate @Test at method level to always have some groups. Finally this should be visible in the sure-fire report , on running it as mvn test.

@Test(testName = "SearchTest" , description ="testing search", ticket="OSQ100")
public class OSQ100_SearchTest {
  
    @Test(groups = {Groups.SMOKE_TEST}, description ="testing data")
    public void validateTitle1Test() {
        RequestSpecification requestSpecification = new RestAssuredConfiguration().getRequestSpecification();
        requestSpecification.queryParam("at", "40.71455,-74.00714").queryParam("q", "hotels").queryParam("app_id", EndPoint.APP_ID_PREMIUM).queryParam("app_code", EndPoint.APP_CODE_PREMIUM).log().all();

        ValidatableResponse validatableResponse = given().spec(requestSpecification).get(EndPoint.DISCOVER_SEARCH_QUERY_PARAM).then();
        validatableResponse.assertThat().body("results.items", hasSize(greaterThan(20)));

       /* String json = given().spec(requestSpecification).get(EndPoint.DISCOVER_SEARCH_QUERY_PARAM).then().extract().asString();
        JsonPath jsonPath = new JsonPath(json).setRoot("results.items");
        System.out.println(jsonPath.get);*/
    }
  }

Thanks in advance!

Rejish

--
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 testng-users...@googlegroups.com.
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.
--

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/

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

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/

--
You received this message because you are subscribed to a topic in the Google Groups "testng-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/testng-users/IKp27WsjaQE/unsubscribe.
To unsubscribe from this group and all its topics, 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.