Is it possible to append Test to the suite at runtime?

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

Is it possible to append Test to the suite at runtime?

dr29bart
import org.testng.ITestContext;
import org.testng.SkipException;
import org.testng.annotations.BeforeClass;
import org.testng.xml.XmlClass;


public abstract class ATest {

   
@BeforeClass
    public void checkAndInit(ITestContext context) {
       
if (TestUtils.isMonday()) {
            context
.getCurrentXmlTest().getXmlClasses().add(new XmlClass(MondayTest.class.getName()));
           
throw new SkipException("Not a good day for test");
       
}

   
}
}

Child test class (BTest extends ATest) is skipped but it looks like the test scope isn't changed.

Tests are started by IDEA from testng xml file 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Z" configfailurepolicy="continue">
    <test name="A">
     <classes>
       
<class name="com.BTest" />
     
</classes>
   
</test>
</suite>


--
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: Is it possible to append Test to the suite at runtime?

Krishnan Mahadevan
For doing this you should be leveraging the listener interface org.testng.IAlterSuiteListener 

That should help you do what you are looking for in terms of adding more tests into your suite in runtime. 

On Fri 29 Jun, 2018, 13:07 Artem Yakovlev, <[hidden email]> wrote:
import org.testng.ITestContext;
import org.testng.SkipException;
import org.testng.annotations.BeforeClass;
import org.testng.xml.XmlClass;


public abstract class ATest {

   
@BeforeClass
    public void checkAndInit(ITestContext context) {
       
if (TestUtils.isMonday()) {
            context
.getCurrentXmlTest().getXmlClasses().add(new XmlClass(MondayTest.class.getName()));
           
throw new SkipException("Not a good day for test");
       
}

   
}
}

Child test class (BTest extends ATest) is skipped but it looks like the test scope isn't changed.

Tests are started by IDEA from testng xml file 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Z" configfailurepolicy="continue">
    <test name="A">
     <classes>
       
<class name="com.BTest" />
     
</classes>
   
</test>
</suite>


--
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: Is it possible to append Test to the suite at runtime?

dr29bart
Thanks for info.
Looks like this listener runs before everything. Is there any option to run IAlterSuiteListener similar to onSuiteStart? 
In my case there are few long running suites 
<listeners>
   
<listener class-name="com.ScopeChangerListener"></listener>
</listeners>
<suite-files>
 
<suite-file path="./mapSuite.xml"/>
 
<suite-file path="./layerSuite.xml"/>
 
<suite-file path="./apiSuite.xml" />
...
</suite-files>

How to alter each child suite before its start?

пятница, 29 июня 2018 г., 13:37:45 UTC+3 пользователь Krishnan Mahadevan написал:
For doing this you should be leveraging the listener interface org.testng.IAlterSuiteListener 

That should help you do what you are looking for in terms of adding more tests into your suite in runtime. 

On Fri 29 Jun, 2018, 13:07 Artem Yakovlev, <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="8RonOhsKCAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">dr29...@...> wrote:
import org.testng.ITestContext;
import org.testng.SkipException;
import org.testng.annotations.BeforeClass;
import org.testng.xml.XmlClass;


public abstract class ATest {

   
@BeforeClass
    public void checkAndInit(ITestContext context) {
       
if (TestUtils.isMonday()) {
            context
.getCurrentXmlTest().getXmlClasses().add(new XmlClass(MondayTest.class.getName()));
           
throw new SkipException("Not a good day for test");
       
}

   
}
}

Child test class (BTest extends ATest) is skipped but it looks like the test scope isn't changed.

Tests are started by IDEA from testng xml file 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "<a href="http://testng.org/testng-1.0.dtd" target="_blank" rel="nofollow" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ftestng.org%2Ftestng-1.0.dtd\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFHihXzQ1YlwcxcDehnw97TuniFLA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ftestng.org%2Ftestng-1.0.dtd\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFHihXzQ1YlwcxcDehnw97TuniFLA&#39;;return true;">http://testng.org/testng-1.0.dtd" >
<suite name="Z" configfailurepolicy="continue">
    <test name="A">
     <classes>
       
<class name="com.BTest" />
     
</classes>
   
</test>
</suite>


--
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="8RonOhsKCAAJ" 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="8RonOhsKCAAJ" 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: Is it possible to append Test to the suite at runtime?

Krishnan Mahadevan
Am afraid there is currently no other way apart from this listener that lets you alter state. 

On Mon 2 Jul, 2018, 02:39 Artem Yakovlev, <[hidden email]> wrote:
Thanks for info.
Looks like this listener runs before everything. Is there any option to run IAlterSuiteListener similar to onSuiteStart? 
In my case there are few long running suites 
<listeners>
   
<listener class-name="com.ScopeChangerListener"></listener>
</listeners>
<suite-files>
 
<suite-file path="./mapSuite.xml"/>
 
<suite-file path="./layerSuite.xml"/>
 
<suite-file path="./apiSuite.xml" />
...
</suite-files>

How to alter each child suite before its start?

пятница, 29 июня 2018 г., 13:37:45 UTC+3 пользователь Krishnan Mahadevan написал:
For doing this you should be leveraging the listener interface org.testng.IAlterSuiteListener 

That should help you do what you are looking for in terms of adding more tests into your suite in runtime. 

On Fri 29 Jun, 2018, 13:07 Artem Yakovlev, <[hidden email]> wrote:
import org.testng.ITestContext;
import org.testng.SkipException;
import org.testng.annotations.BeforeClass;
import org.testng.xml.XmlClass;


public abstract class ATest {

   
@BeforeClass
    public void checkAndInit(ITestContext context) {
       
if (TestUtils.isMonday()) {
            context
.getCurrentXmlTest().getXmlClasses().add(new XmlClass(MondayTest.class.getName()));
           
throw new SkipException("Not a good day for test");
       
}

   
}
}

Child test class (BTest extends ATest) is skipped but it looks like the test scope isn't changed.

Tests are started by IDEA from testng xml file 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Z" configfailurepolicy="continue">
    <test name="A">
     <classes>
       
<class name="com.BTest" />
     
</classes>
   
</test>
</suite>


--
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: Is it possible to append Test to the suite at runtime?

Scott Babcock
You can also alter the collection of tests about to be executed via the IMethodInterceptor listener. Its intercept() method allows you to re-order, add or remove methods prior to execution.

On Sunday, July 1, 2018 at 7:03:46 PM UTC-7, Krishnan Mahadevan wrote:
Am afraid there is currently no other way apart from this listener that lets you alter state. 

On Mon 2 Jul, 2018, 02:39 Artem Yakovlev, <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="09MMm8zZCAAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">dr29...@...> wrote:
Thanks for info.
Looks like this listener runs before everything. Is there any option to run IAlterSuiteListener similar to onSuiteStart? 
In my case there are few long running suites 
<listeners>
   
<listener class-name="com.ScopeChangerListener"></listener>
</listeners>
<suite-files>
 
<suite-file path="./mapSuite.xml"/>
 
<suite-file path="./layerSuite.xml"/>
 
<suite-file path="./apiSuite.xml" />
...
</suite-files>

How to alter each child suite before its start?

пятница, 29 июня 2018 г., 13:37:45 UTC+3 пользователь Krishnan Mahadevan написал:
For doing this you should be leveraging the listener interface org.testng.IAlterSuiteListener 

That should help you do what you are looking for in terms of adding more tests into your suite in runtime. 

On Fri 29 Jun, 2018, 13:07 Artem Yakovlev, <[hidden email]> wrote:
import org.testng.ITestContext;
import org.testng.SkipException;
import org.testng.annotations.BeforeClass;
import org.testng.xml.XmlClass;


public abstract class ATest {

   
@BeforeClass
    public void checkAndInit(ITestContext context) {
       
if (TestUtils.isMonday()) {
            context
.getCurrentXmlTest().getXmlClasses().add(new XmlClass(MondayTest.class.getName()));
           
throw new SkipException("Not a good day for test");
       
}

   
}
}

Child test class (BTest extends ATest) is skipped but it looks like the test scope isn't changed.

Tests are started by IDEA from testng xml file 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "<a href="http://testng.org/testng-1.0.dtd" rel="nofollow" target="_blank" onmousedown="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ftestng.org%2Ftestng-1.0.dtd\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFHihXzQ1YlwcxcDehnw97TuniFLA&#39;;return true;" onclick="this.href=&#39;http://www.google.com/url?q\x3dhttp%3A%2F%2Ftestng.org%2Ftestng-1.0.dtd\x26sa\x3dD\x26sntz\x3d1\x26usg\x3dAFQjCNFHihXzQ1YlwcxcDehnw97TuniFLA&#39;;return true;">http://testng.org/testng-1.0.dtd" >
<suite name="Z" configfailurepolicy="continue">
    <test name="A">
     <classes>
       
<class name="com.BTest" />
     
</classes>
   
</test>
</suite>


--
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 <a href="https://groups.google.com/group/testng-users" rel="nofollow" target="_blank" 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" 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.
--

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.wordpress.com/" rel="nofollow" target="_blank" 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 <a href="javascript:" target="_blank" gdf-obfuscated-mailto="09MMm8zZCAAJ" 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="09MMm8zZCAAJ" 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.