How to get handle of current running testNG instance...

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

How to get handle of current running testNG instance...

shankarkc78@gmail.com
Hi,
   I have a testsuite xml(Failed-testNG.xml) that gets generated dynamically and its not part of test source code. I want to use it as my testNG.xml.
I thought of doing this.

ArrayList<XmlSuite> arrayList = null;

        File failedxml = new File("failed-tesNG.xml");
        logInfo(tcID, "current DIR is " + failedxml.getAbsolutePath());
        if (failedxml.exists() && ReportingListener.maxRerunCount > 0) {
            try {
                arrayList = new ArrayList<XmlSuite>(new Parser(
                        "Failed.xml").parse());
            } catch (ParserConfigurationException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (SAXException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

            TestNG tng = this; // NEED TO GET CURRENT TESTNG INSTANCE and set its XML suite. Not sure how to refer current running testNG instance
            tng.setXmlSuites(arrayList);
.......
........
.......
 
        }
Can anybody guide me how to do it?

My used case scenario is this.
I have bunch of tests that run and some might fail due to environment issue. next day in the workspace i do see failed-testNG.xml produced. i want to rerun it. By default we select the testNG.xml defined in POM. i want to skip it and use the failed-testNG.xml. i assume user sets a SystemProperty called "usedFaildXML" to true. If so i will try to parse the xml and run the tests in it.
Thanks
Shankar KC

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/Y2rlQ4-TGrYJ.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: How to get handle of current running testNG instance...

shankarkc78@gmail.com
Hi can anyone answer this?
Thanks
Shankar KC

On Wednesday, November 7, 2012 12:08:58 PM UTC+5:30, shankar KC wrote:
Hi,
   I have a testsuite xml(Failed-testNG.xml) that gets generated dynamically and its not part of test source code. I want to use it as my testNG.xml.
I thought of doing this.

ArrayList<XmlSuite> arrayList = null;

        File failedxml = new File("failed-tesNG.xml");
        logInfo(tcID, "current DIR is " + failedxml.getAbsolutePath());
        if (failedxml.exists() && ReportingListener.maxRerunCount > 0) {
            try {
                arrayList = new ArrayList<XmlSuite>(new Parser(
                        "Failed.xml").parse());
            } catch (ParserConfigurationException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (SAXException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

            TestNG tng = this; // NEED TO GET CURRENT TESTNG INSTANCE and set its XML suite. Not sure how to refer current running testNG instance
            tng.setXmlSuites(arrayList);
.......
........
.......
 
        }
Can anybody guide me how to do it?

My used case scenario is this.
I have bunch of tests that run and some might fail due to environment issue. next day in the workspace i do see failed-testNG.xml produced. i want to rerun it. By default we select the testNG.xml defined in POM. i want to skip it and use the failed-testNG.xml. i assume user sets a SystemProperty called "usedFaildXML" to true. If so i will try to parse the xml and run the tests in it.
Thanks
Shankar KC

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/vsc1wXLlsxwJ.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: How to get handle of current running testNG instance...

Cédric Beust ♔-2
In reply to this post by shankarkc78@gmail.com
Why not simply modify your build so it uses testng-failed.xml instead fo testng.xml?

-- 
Cédric




On Tue, Nov 6, 2012 at 10:38 PM, shankar KC <[hidden email]> wrote:
Hi,
   I have a testsuite xml(Failed-testNG.xml) that gets generated dynamically and its not part of test source code. I want to use it as my testNG.xml.
I thought of doing this.

ArrayList<XmlSuite> arrayList = null;

        File failedxml = new File("failed-tesNG.xml");
        logInfo(tcID, "current DIR is " + failedxml.getAbsolutePath());
        if (failedxml.exists() && ReportingListener.maxRerunCount > 0) {
            try {
                arrayList = new ArrayList<XmlSuite>(new Parser(
                        "Failed.xml").parse());
            } catch (ParserConfigurationException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (SAXException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

            TestNG tng = this; // NEED TO GET CURRENT TESTNG INSTANCE and set its XML suite. Not sure how to refer current running testNG instance
            tng.setXmlSuites(arrayList);
.......
........
.......
 
        }
Can anybody guide me how to do it?

My used case scenario is this.
I have bunch of tests that run and some might fail due to environment issue. next day in the workspace i do see failed-testNG.xml produced. i want to rerun it. By default we select the testNG.xml defined in POM. i want to skip it and use the failed-testNG.xml. i assume user sets a SystemProperty called "usedFaildXML" to true. If so i will try to parse the xml and run the tests in it.
Thanks
Shankar KC

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/Y2rlQ4-TGrYJ.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: How to get handle of current running testNG instance...

Krishnan Mahadevan
In reply to this post by shankarkc78@gmail.com
Shankar,

Answer to your question : No you cannot get a handle to the currently running TestNG instance, because there is no mechanism defined in it.

If you are using maven, then you could essentially define a property as below :

<properties>
<testSuite>src/test/resources/suiteBuildTests.xml</testSuite>
</properties>
and then refer to this property value in your surefire plugin as below :

<suiteXmlFiles>
<suiteXmlFile>${testSuite}</suiteXmlFile>
</suiteXmlFiles>

In your continuous integration job, you can override the value for this property using the VM arg as 
-DtestSuite=faile-suite.xml

Wouldnt that help ?

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"



On Thu, Nov 8, 2012 at 10:31 AM, shankar KC <[hidden email]> wrote:
Hi can anyone answer this?
Thanks
Shankar KC


On Wednesday, November 7, 2012 12:08:58 PM UTC+5:30, shankar KC wrote:
Hi,
   I have a testsuite xml(Failed-testNG.xml) that gets generated dynamically and its not part of test source code. I want to use it as my testNG.xml.
I thought of doing this.

ArrayList<XmlSuite> arrayList = null;

        File failedxml = new File("failed-tesNG.xml");
        logInfo(tcID, "current DIR is " + failedxml.getAbsolutePath());
        if (failedxml.exists() && ReportingListener.maxRerunCount > 0) {
            try {
                arrayList = new ArrayList<XmlSuite>(new Parser(
                        "Failed.xml").parse());
            } catch (ParserConfigurationException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (SAXException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

            TestNG tng = this; // NEED TO GET CURRENT TESTNG INSTANCE and set its XML suite. Not sure how to refer current running testNG instance
            tng.setXmlSuites(arrayList);
.......
........
.......
 
        }
Can anybody guide me how to do it?

My used case scenario is this.
I have bunch of tests that run and some might fail due to environment issue. next day in the workspace i do see failed-testNG.xml produced. i want to rerun it. By default we select the testNG.xml defined in POM. i want to skip it and use the failed-testNG.xml. i assume user sets a SystemProperty called "usedFaildXML" to true. If so i will try to parse the xml and run the tests in it.
Thanks
Shankar KC

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/vsc1wXLlsxwJ.

To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: How to get handle of current running testNG instance...

shankarkc78@gmail.com
Yes it helps a bit. Ususally when you have multiple testNG suites failed-TestNG.xml produced for each suite and kept in output directory. So its possible that i might have to pass multiple testNG files. I am novice MAVEN user. Is it possible to pass multiple testNG files in some way?

On Thursday, November 8, 2012 11:25:07 AM UTC+5:30, Krishnan wrote:
Shankar,

Answer to your question : No you cannot get a handle to the currently running TestNG instance, because there is no mechanism defined in it.

If you are using maven, then you could essentially define a property as below :

<properties>
<testSuite>src/test/resources/suiteBuildTests.xml</testSuite>
</properties>
and then refer to this property value in your surefire plugin as below :

<suiteXmlFiles>
<suiteXmlFile>${testSuite}</suiteXmlFile>
</suiteXmlFiles>

In your continuous integration job, you can override the value for this property using the VM arg as 
-DtestSuite=faile-suite.xml

Wouldnt that help ?

Thanks & Regards
Krishnan Mahadevan

"All the desirable things in life are either illegal, expensive, fattening or in love with someone else!"



On Thu, Nov 8, 2012 at 10:31 AM, shankar KC <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="T_cjJ12nSz8J">shank...@...> wrote:
Hi can anyone answer this?
Thanks
Shankar KC


On Wednesday, November 7, 2012 12:08:58 PM UTC+5:30, shankar KC wrote:
Hi,
   I have a testsuite xml(Failed-testNG.xml) that gets generated dynamically and its not part of test source code. I want to use it as my testNG.xml.
I thought of doing this.

ArrayList<XmlSuite> arrayList = null;

        File failedxml = new File("failed-tesNG.xml");
        logInfo(tcID, "current DIR is " + failedxml.getAbsolutePath());
        if (failedxml.exists() && ReportingListener.maxRerunCount > 0) {
            try {
                arrayList = new ArrayList<XmlSuite>(new Parser(
                        "Failed.xml").parse());
            } catch (ParserConfigurationException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (SAXException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

            TestNG tng = this; // NEED TO GET CURRENT TESTNG INSTANCE and set its XML suite. Not sure how to refer current running testNG instance
            tng.setXmlSuites(arrayList);
.......
........
.......
 
        }
Can anybody guide me how to do it?

My used case scenario is this.
I have bunch of tests that run and some might fail due to environment issue. next day in the workspace i do see failed-testNG.xml produced. i want to rerun it. By default we select the testNG.xml defined in POM. i want to skip it and use the failed-testNG.xml. i assume user sets a SystemProperty called "usedFaildXML" to true. If so i will try to parse the xml and run the tests in it.
Thanks
Shankar KC

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/vsc1wXLlsxwJ.

To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="T_cjJ12nSz8J">testng...@....
To unsubscribe from this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="T_cjJ12nSz8J">testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/Q4H2SBy7VsUJ.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.
Reply | Threaded
Open this post in threaded view
|

Re: How to get handle of current running testNG instance...

shankarkc78@gmail.com
In reply to this post by Cédric Beust ♔-2
Thanks Cédric. My intent is to provide user ease of use. Now to rerun(approach you suggested ) user need to gather multiple failed-testNG.xml from multiple folders and build/run again. I feel its bit painful. Programatically i can get failed testNGs. But i need to a)  clear the current testNG suite and b) set the failed-testNG.xml as current test suite. But i am not sure how to achieve it.
Thanks
Shankar KC

On Thursday, November 8, 2012 11:22:31 AM UTC+5:30, Cédric Beust ♔ wrote:
Why not simply modify your build so it uses testng-failed.xml instead fo testng.xml?

-- 
Cédric




On Tue, Nov 6, 2012 at 10:38 PM, shankar KC <<a href="javascript:" target="_blank" gdf-obfuscated-mailto="iHmkf8ivbCoJ">shank...@...> wrote:
Hi,
   I have a testsuite xml(Failed-testNG.xml) that gets generated dynamically and its not part of test source code. I want to use it as my testNG.xml.
I thought of doing this.

ArrayList<XmlSuite> arrayList = null;

        File failedxml = new File("failed-tesNG.xml");
        logInfo(tcID, "current DIR is " + failedxml.getAbsolutePath());
        if (failedxml.exists() && ReportingListener.maxRerunCount > 0) {
            try {
                arrayList = new ArrayList<XmlSuite>(new Parser(
                        "Failed.xml").parse());
            } catch (ParserConfigurationException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (SAXException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

            TestNG tng = this; // NEED TO GET CURRENT TESTNG INSTANCE and set its XML suite. Not sure how to refer current running testNG instance
            tng.setXmlSuites(arrayList);
.......
........
.......
 
        }
Can anybody guide me how to do it?

My used case scenario is this.
I have bunch of tests that run and some might fail due to environment issue. next day in the workspace i do see failed-testNG.xml produced. i want to rerun it. By default we select the testNG.xml defined in POM. i want to skip it and use the failed-testNG.xml. i assume user sets a SystemProperty called "usedFaildXML" to true. If so i will try to parse the xml and run the tests in it.
Thanks
Shankar KC

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/Y2rlQ4-TGrYJ.
To post to this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="iHmkf8ivbCoJ">testng...@....
To unsubscribe from this group, send email to <a href="javascript:" target="_blank" gdf-obfuscated-mailto="iHmkf8ivbCoJ">testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/testng-users/-/vEeer5MgtMwJ.
To post to this group, send email to [hidden email].
To unsubscribe from this group, send email to [hidden email].
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.