Remove a test tag from suite.xml file dynamically during run time

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

Remove a test tag from suite.xml file dynamically during run time

Musaffir Lp
Hello,

I am using IAlterSuiteListener to alter my suite xml file ... ( got to knw abt it from this blog post - https://rationaleemotions.wordpress.com/2017/09/29/building-dynamic-testng-suites/ by Krishnan sir ..) ...

basically I have many test tags in my suite xml file ..and I want to dynamicallly remove some test tags during run time ..(or) in another words I want to run only some test tags from the suite ...

Similar to method -  addTest(xmlTest) available to <a class="header" href="eclipse-javadoc:%E2%98%82=CP_TestAutomationFramework/src%5C/main%5C/java%3Cnet.cloudpay.test.suite.driver%7BCPTestSuiteAlterer.java%E2%98%83CPTestSuiteAlterer~alter~QList%5C%3CQXmlSuite;%3E;@suite!407!437!416!420!QXmlSuite;!0!false%E2%98%82XmlSuite">XmlSuite suite object, I couldn't find a method to remove a test tag ...

( the suite object need to be the same ...as I have other listener too added in the same testng suite xml file ...
so once the suite object is modified with  IAlterSuiteListener , the other listener can still act on it ... )

Please let me know if you know how to get this done ..

Thanks
Musaffir

--
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: Remove a test tag from suite.xml file dynamically during run time

Krishnan Mahadevan
When you say test tags, what are you referring to? Can you please help clarify that ?

Using IAlterSuiteListener, you should be able to pretty much do whatever you would like in terms of building a test suite dynamically.

The other approach would be to add the bean-shell capabilities that TestNG provides you, to filter out groups (am guessing you are referring to groups when you say tags).
You can read more about how to leverage a bean-shell method selector to do this from my blog here : 



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 Mon, Oct 30, 2017 at 4:39 PM, Musaffir lp <[hidden email]> wrote:
Hello,

I am using IAlterSuiteListener to alter my suite xml file ... ( got to knw abt it from this blog post - https://rationaleemotions.wordpress.com/2017/09/29/building-dynamic-testng-suites/ by Krishnan sir ..) ...

basically I have many test tags in my suite xml file ..and I want to dynamicallly remove some test tags during run time ..(or) in another words I want to run only some test tags from the suite ...

Similar to method -  addTest(xmlTest) available to XmlSuite suite object, I couldn't find a method to remove a test tag ...

( the suite object need to be the same ...as I have other listener too added in the same testng suite xml file ...
so once the suite object is modified with  IAlterSuiteListener , the other listener can still act on it ... )

Please let me know if you know how to get this done ..

Thanks
Musaffir

--
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.
Reply | Threaded
Open this post in threaded view
|

Re: Remove a test tag from suite.xml file dynamically during run time

Musaffir Lp
Hi Krishnan,

By test tag I meant the <test name=sometest > which is already present in my suite xml file.. ( each test has single / more classes ) .. My testng suite xml is an already existing one in which i have multiple <tests>.. by default when i execute the suite xml , all tests will be executed.

But in some situation, I wanted to pick only a single / more than one particular tests from the suite file.
I wanted to acheive this during run time and do not want to edit the xml file everytime before runningn suite..

Thanks
Musaffir

On Monday, October 30, 2017, ⇜Krishnan Mahadevan⇝ <[hidden email]> wrote:
When you say test tags, what are you referring to? Can you please help clarify that ?

Using IAlterSuiteListener, you should be able to pretty much do whatever you would like in terms of building a test suite dynamically.

The other approach would be to add the bean-shell capabilities that TestNG provides you, to filter out groups (am guessing you are referring to groups when you say tags).
You can read more about how to leverage a bean-shell method selector to do this from my blog here : 



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 Mon, Oct 30, 2017 at 4:39 PM, Musaffir lp <<a href="javascript:_e(%7B%7D,&#39;cvml&#39;,&#39;musaffirlp@gmail.com&#39;);" target="_blank">musaffirlp@...> wrote:
Hello,

I am using IAlterSuiteListener to alter my suite xml file ... ( got to knw abt it from this blog post - https://rationaleemotions.wordpress.com/2017/09/29/building-dynamic-testng-suites/ by Krishnan sir ..) ...

basically I have many test tags in my suite xml file ..and I want to dynamicallly remove some test tags during run time ..(or) in another words I want to run only some test tags from the suite ...

Similar to method -  addTest(xmlTest) available to XmlSuite suite object, I couldn't find a method to remove a test tag ...

( the suite object need to be the same ...as I have other listener too added in the same testng suite xml file ...
so once the suite object is modified with  IAlterSuiteListener , the other listener can still act on it ... )

Please let me know if you know how to get this done ..

Thanks
Musaffir

--
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:_e(%7B%7D,&#39;cvml&#39;,&#39;testng-users%2Bunsubscribe@googlegroups.com&#39;);" target="_blank">testng-users+unsubscribe@googlegroups.com.
To post to this group, send email to <a href="javascript:_e(%7B%7D,&#39;cvml&#39;,&#39;testng-users@googlegroups.com&#39;);" target="_blank">testng-users@....
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 a topic in the Google Groups "testng-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/testng-users/XNiNe-cFEMo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to <a href="javascript:_e(%7B%7D,&#39;cvml&#39;,&#39;testng-users%2Bunsubscribe@googlegroups.com&#39;);" target="_blank">testng-users+unsubscribe@googlegroups.com.
To post to this group, send email to <a href="javascript:_e(%7B%7D,&#39;cvml&#39;,&#39;testng-users@googlegroups.com&#39;);" target="_blank">testng-users@....
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.
Reply | Threaded
Open this post in threaded view
|

Re: Remove a test tag from suite.xml file dynamically during run time

Musaffir Lp
Hi Krishnan,

Some how I could manage to do what I was looking for ... I am glad your post really helped me :)
I am overriding the alter method as below ....

The testNg suite xml is an already defined one ... which has multiple tests and each tests got a name as we do normally ....
Now I am giving the user a flexibility to choose a test name(s) during run time if user wish to do it .... 

@Override
   
public void alter(List<XmlSuite> suites)
   
{
       
/*User is passing the test tag names here that he/she wish to execute.
         *This is going to be a Multi select parameter from Jenkin .. active choice parameter allows multi select
         *
         */

       
       
String testsToExecute = System.getProperty("testNames","");
       
// Alter the suite object only if testNames passed is not empty
       
if(!testsToExecute.equals(""))
       
{
           
String[] testsPassedByUser = testsToExecute.split(",");
           
XmlSuite suite = suites.get(0);
           
List<XmlTest> xmlTests = suite.getTests();

           
ArrayList<XmlTest> newXMLTests = new ArrayList<XmlTest>();

           
for (String testName : testsPassedByUser)
           
{                                
               
for (XmlTest xmlTest : xmlTests)
                   
{
                       
String name = xmlTest.getName();
                       
if(name.equalsIgnoreCase(testName))
                       
{
                            newXMLTests
.add(xmlTest);
                       
}
                   
}    
           
}
           
// suite object is altered here with the new set of xml tests
            suite
.setTests(newXMLTests);

   
}

}



Thanks & Warm Regards
Musaffir



On Monday, October 30, 2017 at 11:30:03 PM UTC+8, Musaffir lp wrote:
Hi Krishnan,

By test tag I meant the <test name=sometest > which is already present in my suite xml file.. ( each test has single / more classes ) .. My testng suite xml is an already existing one in which i have multiple <tests>.. by default when i execute the suite xml , all tests will be executed.

But in some situation, I wanted to pick only a single / more than one particular tests from the suite file.
I wanted to acheive this during run time and do not want to edit the xml file everytime before runningn suite..

Thanks
Musaffir

On Monday, October 30, 2017, ⇜Krishnan Mahadevan⇝ <[hidden email]> wrote:
When you say test tags, what are you referring to? Can you please help clarify that ?

Using IAlterSuiteListener, you should be able to pretty much do whatever you would like in terms of building a test suite dynamically.

The other approach would be to add the bean-shell capabilities that TestNG provides you, to filter out groups (am guessing you are referring to groups when you say tags).
You can read more about how to leverage a bean-shell method selector to do this from my blog here : 

<a href="https://rationaleemotions.wordpress.com/2013/08/21/beanshell-and-testng/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Frationaleemotions.wordpress.com%2F2013%2F08%2F21%2Fbeanshell-and-testng%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGxnd7N61D8RcvumTZjyNRoVMkuKg&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Frationaleemotions.wordpress.com%2F2013%2F08%2F21%2Fbeanshell-and-testng%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNGxnd7N61D8RcvumTZjyNRoVMkuKg&#39;;return true;">https://rationaleemotions.wordpress.com/2013/08/21/beanshell-and-testng/


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/

On Mon, Oct 30, 2017 at 4:39 PM, Musaffir lp <[hidden email]> wrote:
Hello,

I am using IAlterSuiteListener to alter my suite xml file ... ( got to knw abt it from this blog post - <a href="https://rationaleemotions.wordpress.com/2017/09/29/building-dynamic-testng-suites/" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Frationaleemotions.wordpress.com%2F2017%2F09%2F29%2Fbuilding-dynamic-testng-suites%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH7uV44U1oPz_7vwCzVllTtk5nSxw&#39;;return true;" onclick="this.href=&#39;https://www.google.com/url?q\x3dhttps%3A%2F%2Frationaleemotions.wordpress.com%2F2017%2F09%2F29%2Fbuilding-dynamic-testng-suites%2F\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNH7uV44U1oPz_7vwCzVllTtk5nSxw&#39;;return true;">https://rationaleemotions.wordpress.com/2017/09/29/building-dynamic-testng-suites/ by Krishnan sir ..) ...

basically I have many test tags in my suite xml file ..and I want to dynamicallly remove some test tags during run time ..(or) in another words I want to run only some test tags from the suite ...

Similar to method -  addTest(xmlTest) available to XmlSuite suite object, I couldn't find a method to remove a test tag ...

( the suite object need to be the same ...as I have other listener too added in the same testng suite xml file ...
so once the suite object is modified with  IAlterSuiteListener , the other listener can still act on it ... )

Please let me know if you know how to get this done ..

Thanks
Musaffir

--
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+unsubscribe@googlegroups.com.
To post to this group, send email to [hidden email].
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.

--
You received this message because you are subscribed to a topic in the Google Groups "testng-users" group.
To unsubscribe from this topic, visit <a href="https://groups.google.com/d/topic/testng-users/XNiNe-cFEMo/unsubscribe" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/d/topic/testng-users/XNiNe-cFEMo/unsubscribe&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/d/topic/testng-users/XNiNe-cFEMo/unsubscribe&#39;;return true;">https://groups.google.com/d/topic/testng-users/XNiNe-cFEMo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to testng-users+unsubscribe@googlegroups.com.
To post to this group, send email to [hidden email].
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.

--
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: Remove a test tag from suite.xml file dynamically during run time

Krishnan Mahadevan

Perfect! Glad you figured this out on your own

 

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/

 

From: <[hidden email]> on behalf of Musaffir lp <[hidden email]>
Reply-To: <[hidden email]>
Date: Tuesday, October 31, 2017 at 9:00 AM
To: testng-users <[hidden email]>
Subject: Re: [testng-users] Remove a test tag from suite.xml file dynamically during run time

 

Hi Krishnan,

Some how I could manage to do what I was looking for ... I am glad your post really helped me :)
I am overriding the alter method as below ....

The testNg suite xml is an already defined one ... which has multiple tests and each tests got a name as we do normally ....
Now I am giving the user a flexibility to choose a test name(s) during run time if user wish to do it .... 

@Override
   
public void alter(List<XmlSuite> suites)
   
{
       
/*User is passing the test tag names here that he/she wish to execute.
         *This is going to be a Multi select parameter from Jenkin .. active choice parameter allows multi select
         *
         */

       
       
String testsToExecute = System.getProperty("testNames","");
       
// Alter the suite object only if testNames passed is not empty
       
if(!testsToExecute.equals(""))
       
{
           
String[] testsPassedByUser = testsToExecute.split(",");
           
XmlSuite suite = suites.get(0);
           
List<XmlTest> xmlTests = suite.getTests();

           
ArrayList<XmlTest> newXMLTests = new ArrayList<XmlTest>();

           
for (String testName : testsPassedByUser)
           
{                                
               
for (XmlTest xmlTest : xmlTests)
                   
{
                       
String name = xmlTest.getName();
                       
if(name.equalsIgnoreCase(testName))
                       
{
                            newXMLTests
.add(xmlTest);
                       
}
                   
}    
           
}
           
// suite object is altered here with the new set of xml tests
            suite
.setTests(newXMLTests);

   
}

}




Thanks & Warm Regards
Musaffir



On Monday, October 30, 2017 at 11:30:03 PM UTC+8, Musaffir lp wrote:

Hi Krishnan,

 

By test tag I meant the <test name=sometest > which is already present in my suite xml file.. ( each test has single / more classes ) .. My testng suite xml is an already existing one in which i have multiple <tests>.. by default when i execute the suite xml , all tests will be executed.

 

But in some situation, I wanted to pick only a single / more than one particular tests from the suite file.

I wanted to acheive this during run time and do not want to edit the xml file everytime before runningn suite..

 

Thanks

Musaffir

On Monday, October 30, 2017, Krishnan Mahadevan <[hidden email]> wrote:

When you say test tags, what are you referring to? Can you please help clarify that ?

 

Using IAlterSuiteListener, you should be able to pretty much do whatever you would like in terms of building a test suite dynamically.

 

The other approach would be to add the bean-shell capabilities that TestNG provides you, to filter out groups (am guessing you are referring to groups when you say tags).

You can read more about how to leverage a bean-shell method selector to do this from my blog here : 

 

 


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 Mon, Oct 30, 2017 at 4:39 PM, Musaffir lp <[hidden email]> wrote:

Hello,

I am using IAlterSuiteListener to alter my suite xml file ... ( got to knw abt it from this blog post - https://rationaleemotions.wordpress.com/2017/09/29/building-dynamic-testng-suites/ by Krishnan sir ..) ...

basically I have many test tags in my suite xml file ..and I want to dynamicallly remove some test tags during run time ..(or) in another words I want to run only some test tags from the suite ...

Similar to method -  addTest(xmlTest) available to XmlSuite suite object, I couldn't find a method to remove a test tag ...

( the suite object need to be the same ...as I have other listener too added in the same testng suite xml file ...
so once the suite object is modified with  IAlterSuiteListener , the other listener can still act on it ... )

Please let me know if you know how to get this done ..

Thanks
Musaffir

--
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 a topic in the Google Groups "testng-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/testng-users/XNiNe-cFEMo/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.

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