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

398 views
Skip to first unread message

Musaffir lp

unread,
Oct 30, 2017, 7:09:46 AM10/30/17
to testng-users
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

⇜Krishnan Mahadevan⇝

unread,
Oct 30, 2017, 7:15:32 AM10/30/17
to testng...@googlegroups.com
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/

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

Musaffir lp

unread,
Oct 30, 2017, 11:30:03 AM10/30/17
to testng...@googlegroups.com
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
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 testng-users+unsubscribe@googlegroups.com.

Musaffir lp

unread,
Oct 30, 2017, 11:30:05 PM10/30/17
to testng-users
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

Krishnan Mahadevan

unread,
Oct 31, 2017, 12:04:31 AM10/31/17
to testng...@googlegroups.com

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/

 

Musaffir



On Monday, October 30, 2017, Krishnan Mahadevan <krishnan.ma...@gmail.com> 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 <musaf...@gmail.com> 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 testng-users...@googlegroups.com.


To post to this group, send email to testng...@googlegroups.com.
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 testng-users...@googlegroups.com.


To post to this group, send email to testng...@googlegroups.com.
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 testng-users...@googlegroups.com.

Reply all
Reply to author
Forward
0 new messages