How to add tests programmatically to current suite xml

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

How to add tests programmatically to current suite xml

Tatery
Hello,

I'd like to execute tests using testng xml and maven but in addition to that some tests have to be run programmatically. It means that some tests from xml suite have to run other tests programmatically and afterwards I'd like to have only one test report. 
Do you know if something like this is possible?

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

Re: How to add tests programmatically to current suite xml

Tatery
@Cedric is there a way to modify testNg context at runtime? This would be really nice feature :)

W dniu poniedziałek, 8 maja 2017 10:37:14 UTC+2 użytkownik Tatery napisał:
Hello,

I'd like to execute tests using testng xml and maven but in addition to that some tests have to be run programmatically. It means that some tests from xml suite have to run other tests programmatically and afterwards I'd like to have only one test report. 
Do you know if something like this is possible?

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

Re: How to add tests programmatically to current suite xml

Cédric Beust ♔-2
It might be but it's not supported, so the behavior is undefined.

Adding tests dynamically is typically performed by factories or data providers, wouldn't that work for you?


-- 
Cédric


On Mon, May 8, 2017 at 2:12 PM, Tatery <[hidden email]> wrote:
@Cedric is there a way to modify testNg context at runtime? This would be really nice feature :)


W dniu poniedziałek, 8 maja 2017 10:37:14 UTC+2 użytkownik Tatery napisał:
Hello,

I'd like to execute tests using testng xml and maven but in addition to that some tests have to be run programmatically. It means that some tests from xml suite have to run other tests programmatically and afterwards I'd like to have only one test report. 
Do you know if something like this is possible?

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

Re: How to add tests programmatically to current suite xml

Tatery
Many thanks for the prompt reply.
I very often use factories and data providers but this time both of them do not cover all my requirements. I'm looking for a way to execute existing tests programmatically as part of bigger test suite. Since context modifying at runtime is not possible what do you thing about other approach: read xml suite in @BeforeSuite method then add new tests programmatically and execute tests based on this new in memory suite:

@BeforeSuite
public void initTestProg(ITestContext context) throws InterruptedException {
XmlSuite xmlSuite = context.getCurrentXmlTest().getSuite();
// Create an instance of XmlTest and assign a name for it.
XmlTest xmlTest = new XmlTest(xmlSuite);
xmlTest.setName("Sample Test");

// Create a list which can contain the classes that you want to run.
List<XmlClass> myClasses = new ArrayList<XmlClass>();
myClasses.add(new XmlClass("testing.testngtst.Basic1"));
myClasses.add(new XmlClass("testing.testngtst.Basic2"));

// Assign that to the XmlTest Object created earlier.
xmlTest.setXmlClasses(myClasses);
//....(more code here)

testNG.setXmlSuites(mySuites);
testNG.run();

}


But how to break execution of the original suite at the end of @BeforeSuite method?

Do you have any thoughts how to implement context modifying at runtime? I don't know testNg implementation in details but if you give me some hints I could try to implement this feature.


W dniu poniedziałek, 8 maja 2017 23:15:35 UTC+2 użytkownik Cédric Beust ♔ napisał:
It might be but it's not supported, so the behavior is undefined.

Adding tests dynamically is typically performed by factories or data providers, wouldn't that work for you?


-- 
Cédric


On Mon, May 8, 2017 at 2:12 PM, Tatery <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="s4Kf9lkbEgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">tatery...@...> wrote:
@Cedric is there a way to modify testNg context at runtime? This would be really nice feature :)


W dniu poniedziałek, 8 maja 2017 10:37:14 UTC+2 użytkownik Tatery napisał:
Hello,

I'd like to execute tests using testng xml and maven but in addition to that some tests have to be run programmatically. It means that some tests from xml suite have to run other tests programmatically and afterwards I'd like to have only one test report. 
Do you know if something like this is possible?

--
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="s4Kf9lkbEgAJ" 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="s4Kf9lkbEgAJ" 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.

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

Re: How to add tests programmatically to current suite xml

Cédric Beust ♔-2

With this code, you would run a TestNG inside a TestNG. It would work but the reports at the end would probably be confusing.

Maybe you could take over the whole process and in your own main(), create an XmlSuite that is the sum of testng.xml and your own programmatically created tests, and then invoke testng.run().


-- 
Cédric


On Mon, May 8, 2017 at 2:55 PM, Tatery <[hidden email]> wrote:
Many thanks for the prompt reply.
I very often use factories and data providers but this time both of them do not cover all my requirements. I'm looking for a way to execute existing tests programmatically as part of bigger test suite. Since context modifying at runtime is not possible what do you thing about other approach: read xml suite in @BeforeSuite method then add new tests programmatically and execute tests based on this new in memory suite:

@BeforeSuite
public void initTestProg(ITestContext context) throws InterruptedException {
XmlSuite xmlSuite = context.getCurrentXmlTest().getSuite();
// Create an instance of XmlTest and assign a name for it.
XmlTest xmlTest = new XmlTest(xmlSuite);
xmlTest.setName("Sample Test");

// Create a list which can contain the classes that you want to run.
List<XmlClass> myClasses = new ArrayList<XmlClass>();
myClasses.add(new XmlClass("testing.testngtst.Basic1"));
myClasses.add(new XmlClass("testing.testngtst.Basic2"));

// Assign that to the XmlTest Object created earlier.
xmlTest.setXmlClasses(myClasses);
//....(more code here)

testNG.setXmlSuites(mySuites);
testNG.run();

}


But how to break execution of the original suite at the end of @BeforeSuite method?

Do you have any thoughts how to implement context modifying at runtime? I don't know testNg implementation in details but if you give me some hints I could try to implement this feature.


W dniu poniedziałek, 8 maja 2017 23:15:35 UTC+2 użytkownik Cédric Beust ♔ napisał:
It might be but it's not supported, so the behavior is undefined.

Adding tests dynamically is typically performed by factories or data providers, wouldn't that work for you?


-- 
Cédric


On Mon, May 8, 2017 at 2:12 PM, Tatery <[hidden email]> wrote:
@Cedric is there a way to modify testNg context at runtime? This would be really nice feature :)


W dniu poniedziałek, 8 maja 2017 10:37:14 UTC+2 użytkownik Tatery napisał:
Hello,

I'd like to execute tests using testng xml and maven but in addition to that some tests have to be run programmatically. It means that some tests from xml suite have to run other tests programmatically and afterwards I'd like to have only one test report. 
Do you know if something like this is possible?

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

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

Re: How to add tests programmatically to current suite xml

Krishnan Mahadevan

@Tatery

I think you can try upgrading to the latest version of TestNG and then try leveraging the listener IAlterSuiteListener. This interface let's you alter the suite contents programmatically via listeners.

Please see this thread for more info.

https://groups.google.com/forum/m/#!topic/testng-users/u4HwjBEUzhY


On Tue, May 9, 2017, 03:53 Cédric Beust ♔ <[hidden email]> wrote:

With this code, you would run a TestNG inside a TestNG. It would work but the reports at the end would probably be confusing.

Maybe you could take over the whole process and in your own main(), create an XmlSuite that is the sum of testng.xml and your own programmatically created tests, and then invoke testng.run().


-- 
Cédric


On Mon, May 8, 2017 at 2:55 PM, Tatery <[hidden email]> wrote:
Many thanks for the prompt reply.
I very often use factories and data providers but this time both of them do not cover all my requirements. I'm looking for a way to execute existing tests programmatically as part of bigger test suite. Since context modifying at runtime is not possible what do you thing about other approach: read xml suite in @BeforeSuite method then add new tests programmatically and execute tests based on this new in memory suite:

@BeforeSuite
public void initTestProg(ITestContext context) throws InterruptedException {
XmlSuite xmlSuite = context.getCurrentXmlTest().getSuite();
// Create an instance of XmlTest and assign a name for it.
XmlTest xmlTest = new XmlTest(xmlSuite);
xmlTest.setName("Sample Test");

// Create a list which can contain the classes that you want to run.
List<XmlClass> myClasses = new ArrayList<XmlClass>();
myClasses.add(new XmlClass("testing.testngtst.Basic1"));
myClasses.add(new XmlClass("testing.testngtst.Basic2"));

// Assign that to the XmlTest Object created earlier.
xmlTest.setXmlClasses(myClasses);
//....(more code here)

testNG.setXmlSuites(mySuites);
testNG.run();

}


But how to break execution of the original suite at the end of @BeforeSuite method?

Do you have any thoughts how to implement context modifying at runtime? I don't know testNg implementation in details but if you give me some hints I could try to implement this feature.


W dniu poniedziałek, 8 maja 2017 23:15:35 UTC+2 użytkownik Cédric Beust ♔ napisał:
It might be but it's not supported, so the behavior is undefined.

Adding tests dynamically is typically performed by factories or data providers, wouldn't that work for you?


-- 
Cédric


On Mon, May 8, 2017 at 2:12 PM, Tatery <[hidden email]> wrote:
@Cedric is there a way to modify testNg context at runtime? This would be really nice feature :)


W dniu poniedziałek, 8 maja 2017 10:37:14 UTC+2 użytkownik Tatery napisał:
Hello,

I'd like to execute tests using testng xml and maven but in addition to that some tests have to be run programmatically. It means that some tests from xml suite have to run other tests programmatically and afterwards I'd like to have only one test report. 
Do you know if something like this is possible?

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

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

Re: How to add tests programmatically to current suite xml

Tatery
@Krishnan from my point of view there is no significant difference in running tests programmatically with "old way" and with IAlterSuiteListener. I use ReportNg and after tests execution methods from classes handled with IAlterSuiteListener are not available on report.

W dniu wtorek, 9 maja 2017 03:21:40 UTC+2 użytkownik Krishnan napisał:

@Tatery

I think you can try upgrading to the latest version of TestNG and then try leveraging the listener IAlterSuiteListener. This interface let's you alter the suite contents programmatically via listeners.

Please see this thread for more info.

<a href="https://groups.google.com/forum/m/#!topic/testng-users/u4HwjBEUzhY" target="_blank" rel="nofollow" onmousedown="this.href=&#39;https://groups.google.com/forum/m/#!topic/testng-users/u4HwjBEUzhY&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/forum/m/#!topic/testng-users/u4HwjBEUzhY&#39;;return true;">https://groups.google.com/forum/m/#!topic/testng-users/u4HwjBEUzhY


On Tue, May 9, 2017, 03:53 Cédric Beust ♔ <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="GQIbvMcoEgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">ced...@...> wrote:

With this code, you would run a TestNG inside a TestNG. It would work but the reports at the end would probably be confusing.

Maybe you could take over the whole process and in your own main(), create an XmlSuite that is the sum of testng.xml and your own programmatically created tests, and then invoke testng.run().


-- 
Cédric


On Mon, May 8, 2017 at 2:55 PM, Tatery <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="GQIbvMcoEgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">tatery...@...> wrote:
Many thanks for the prompt reply.
I very often use factories and data providers but this time both of them do not cover all my requirements. I'm looking for a way to execute existing tests programmatically as part of bigger test suite. Since context modifying at runtime is not possible what do you thing about other approach: read xml suite in @BeforeSuite method then add new tests programmatically and execute tests based on this new in memory suite:

@BeforeSuite
public void initTestProg(ITestContext context) throws InterruptedException {
XmlSuite xmlSuite = context.getCurrentXmlTest().getSuite();
// Create an instance of XmlTest and assign a name for it.
XmlTest xmlTest = new XmlTest(xmlSuite);
xmlTest.setName("Sample Test");

// Create a list which can contain the classes that you want to run.
List<XmlClass> myClasses = new ArrayList<XmlClass>();
myClasses.add(new XmlClass("testing.testngtst.Basic1"));
myClasses.add(new XmlClass("testing.testngtst.Basic2"));

// Assign that to the XmlTest Object created earlier.
xmlTest.setXmlClasses(myClasses);
//....(more code here)

testNG.setXmlSuites(mySuites);
testNG.run();

}


But how to break execution of the original suite at the end of @BeforeSuite method?

Do you have any thoughts how to implement context modifying at runtime? I don't know testNg implementation in details but if you give me some hints I could try to implement this feature.


W dniu poniedziałek, 8 maja 2017 23:15:35 UTC+2 użytkownik Cédric Beust ♔ napisał:
It might be but it's not supported, so the behavior is undefined.

Adding tests dynamically is typically performed by factories or data providers, wouldn't that work for you?


-- 
Cédric


On Mon, May 8, 2017 at 2:12 PM, Tatery <[hidden email]> wrote:
@Cedric is there a way to modify testNg context at runtime? This would be really nice feature :)


W dniu poniedziałek, 8 maja 2017 10:37:14 UTC+2 użytkownik Tatery napisał:
Hello,

I'd like to execute tests using testng xml and maven but in addition to that some tests have to be run programmatically. It means that some tests from xml suite have to run other tests programmatically and afterwards I'd like to have only one test report. 
Do you know if something like this is possible?

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

--
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="GQIbvMcoEgAJ" 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="GQIbvMcoEgAJ" 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.

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

Re: How to add tests programmatically to current suite xml

Krishnan Mahadevan

If ReportNG is generating reports via an implementation of IReporter interface implementation then this should not happen. If it's doing via some other listener implementation mechanism then yes it could very well be possible.


On Wed, May 10, 2017, 01:43 Tatery <[hidden email]> wrote:
@Krishnan from my point of view there is no significant difference in running tests programmatically with "old way" and with IAlterSuiteListener. I use ReportNg and after tests execution methods from classes handled with IAlterSuiteListener are not available on report.

W dniu wtorek, 9 maja 2017 03:21:40 UTC+2 użytkownik Krishnan napisał:

@Tatery

I think you can try upgrading to the latest version of TestNG and then try leveraging the listener IAlterSuiteListener. This interface let's you alter the suite contents programmatically via listeners.

Please see this thread for more info.

https://groups.google.com/forum/m/#!topic/testng-users/u4HwjBEUzhY


On Tue, May 9, 2017, 03:53 Cédric Beust ♔ <[hidden email]> wrote:

With this code, you would run a TestNG inside a TestNG. It would work but the reports at the end would probably be confusing.

Maybe you could take over the whole process and in your own main(), create an XmlSuite that is the sum of testng.xml and your own programmatically created tests, and then invoke testng.run().


-- 
Cédric


On Mon, May 8, 2017 at 2:55 PM, Tatery <[hidden email]> wrote:
Many thanks for the prompt reply.
I very often use factories and data providers but this time both of them do not cover all my requirements. I'm looking for a way to execute existing tests programmatically as part of bigger test suite. Since context modifying at runtime is not possible what do you thing about other approach: read xml suite in @BeforeSuite method then add new tests programmatically and execute tests based on this new in memory suite:

@BeforeSuite
public void initTestProg(ITestContext context) throws InterruptedException {
XmlSuite xmlSuite = context.getCurrentXmlTest().getSuite();
// Create an instance of XmlTest and assign a name for it.
XmlTest xmlTest = new XmlTest(xmlSuite);
xmlTest.setName("Sample Test");

// Create a list which can contain the classes that you want to run.
List<XmlClass> myClasses = new ArrayList<XmlClass>();
myClasses.add(new XmlClass("testing.testngtst.Basic1"));
myClasses.add(new XmlClass("testing.testngtst.Basic2"));

// Assign that to the XmlTest Object created earlier.
xmlTest.setXmlClasses(myClasses);
//....(more code here)

testNG.setXmlSuites(mySuites);
testNG.run();

}


But how to break execution of the original suite at the end of @BeforeSuite method?

Do you have any thoughts how to implement context modifying at runtime? I don't know testNg implementation in details but if you give me some hints I could try to implement this feature.


W dniu poniedziałek, 8 maja 2017 23:15:35 UTC+2 użytkownik Cédric Beust ♔ napisał:
It might be but it's not supported, so the behavior is undefined.

Adding tests dynamically is typically performed by factories or data providers, wouldn't that work for you?


-- 
Cédric


On Mon, May 8, 2017 at 2:12 PM, Tatery <[hidden email]> wrote:
@Cedric is there a way to modify testNg context at runtime? This would be really nice feature :)


W dniu poniedziałek, 8 maja 2017 10:37:14 UTC+2 użytkownik Tatery napisał:
Hello,

I'd like to execute tests using testng xml and maven but in addition to that some tests have to be run programmatically. It means that some tests from xml suite have to run other tests programmatically and afterwards I'd like to have only one test report. 
Do you know if something like this is possible?

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

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

Re: How to add tests programmatically to current suite xml

Tatery
For sure, ReportNG use IReporter. 
In this example: https://github.com/cbeust/testng/blob/master/src/test/java/test/listeners/AlterSuiteListenerTest.java, class AlterSuiteListener1SampleTest is implemented inside "main" class AlterSuiteListenerTest1, in this case test methods from AlterSuiteListener1SampleTest are available in report. However, when you move AlterSuiteListener1SampleTest to separate file then methods are not attached to report. Any idea what is wrong?

W dniu środa, 10 maja 2017 03:28:01 UTC+2 użytkownik Krishnan napisał:

If ReportNG is generating reports via an implementation of IReporter interface implementation then this should not happen. If it's doing via some other listener implementation mechanism then yes it could very well be possible.


On Wed, May 10, 2017, 01:43 Tatery <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="zRjv07R3EgAJ" rel="nofollow" onmousedown="this.href=&#39;javascript:&#39;;return true;" onclick="this.href=&#39;javascript:&#39;;return true;">tatery...@...> wrote:
@Krishnan from my point of view there is no significant difference in running tests programmatically with "old way" and with IAlterSuiteListener. I use ReportNg and after tests execution methods from classes handled with IAlterSuiteListener are not available on report.

W dniu wtorek, 9 maja 2017 03:21:40 UTC+2 użytkownik Krishnan napisał:

@Tatery

I think you can try upgrading to the latest version of TestNG and then try leveraging the listener IAlterSuiteListener. This interface let's you alter the suite contents programmatically via listeners.

Please see this thread for more info.

<a href="https://groups.google.com/forum/m/#!topic/testng-users/u4HwjBEUzhY" rel="nofollow" target="_blank" onmousedown="this.href=&#39;https://groups.google.com/forum/m/#!topic/testng-users/u4HwjBEUzhY&#39;;return true;" onclick="this.href=&#39;https://groups.google.com/forum/m/#!topic/testng-users/u4HwjBEUzhY&#39;;return true;">https://groups.google.com/forum/m/#!topic/testng-users/u4HwjBEUzhY


On Tue, May 9, 2017, 03:53 Cédric Beust ♔ <[hidden email]> wrote:

With this code, you would run a TestNG inside a TestNG. It would work but the reports at the end would probably be confusing.

Maybe you could take over the whole process and in your own main(), create an XmlSuite that is the sum of testng.xml and your own programmatically created tests, and then invoke testng.run().


-- 
Cédric


On Mon, May 8, 2017 at 2:55 PM, Tatery <[hidden email]> wrote:
Many thanks for the prompt reply.
I very often use factories and data providers but this time both of them do not cover all my requirements. I'm looking for a way to execute existing tests programmatically as part of bigger test suite. Since context modifying at runtime is not possible what do you thing about other approach: read xml suite in @BeforeSuite method then add new tests programmatically and execute tests based on this new in memory suite:

@BeforeSuite
public void initTestProg(ITestContext context) throws InterruptedException {
XmlSuite xmlSuite = context.getCurrentXmlTest().getSuite();
// Create an instance of XmlTest and assign a name for it.
XmlTest xmlTest = new XmlTest(xmlSuite);
xmlTest.setName("Sample Test");

// Create a list which can contain the classes that you want to run.
List<XmlClass> myClasses = new ArrayList<XmlClass>();
myClasses.add(new XmlClass("testing.testngtst.Basic1"));
myClasses.add(new XmlClass("testing.testngtst.Basic2"));

// Assign that to the XmlTest Object created earlier.
xmlTest.setXmlClasses(myClasses);
//....(more code here)

testNG.setXmlSuites(mySuites);
testNG.run();

}


But how to break execution of the original suite at the end of @BeforeSuite method?

Do you have any thoughts how to implement context modifying at runtime? I don't know testNg implementation in details but if you give me some hints I could try to implement this feature.


W dniu poniedziałek, 8 maja 2017 23:15:35 UTC+2 użytkownik Cédric Beust ♔ napisał:
It might be but it's not supported, so the behavior is undefined.

Adding tests dynamically is typically performed by factories or data providers, wouldn't that work for you?


-- 
Cédric


On Mon, May 8, 2017 at 2:12 PM, Tatery <[hidden email]> wrote:
@Cedric is there a way to modify testNg context at runtime? This would be really nice feature :)


W dniu poniedziałek, 8 maja 2017 10:37:14 UTC+2 użytkownik Tatery napisał:
Hello,

I'd like to execute tests using testng xml and maven but in addition to that some tests have to be run programmatically. It means that some tests from xml suite have to run other tests programmatically and afterwards I'd like to have only one test report. 
Do you know if something like this is possible?

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

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

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

Re: How to add tests programmatically to current suite xml

Ashish khanna
In reply to this post by Tatery

Hello,

I also want to execute my TestNg Testsuite  programmatically but It shows configuration failure when I try to run it. The reason which I got is that it is not able to run Before and After Annotation.
Can anyone help me with it.

List<XmlSuite> suites = new ArrayList<XmlSuite>();
suites.add(suite);
TestNG tng = new TestNG();
tng.setXmlSuites(suites);
tng.run();

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