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

583 views
Skip to first unread message

shankar KC

unread,
Nov 7, 2012, 1:38:58 AM11/7/12
to testng...@googlegroups.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

shankar KC

unread,
Nov 8, 2012, 12:01:03 AM11/8/12
to testng...@googlegroups.com
Hi can anyone answer this?
Thanks
Shankar KC

Cédric Beust ♔

unread,
Nov 8, 2012, 12:52:06 AM11/8/12
to testng...@googlegroups.com
Why not simply modify your build so it uses testng-failed.xml instead fo testng.xml?

-- 
Cédric





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 testng...@googlegroups.com.
To unsubscribe from this group, send email to testng-users...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/testng-users?hl=en.

Krishnan Mahadevan

unread,
Nov 8, 2012, 12:54:54 AM11/8/12
to testng...@googlegroups.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!"



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

shankar KC

unread,
Nov 8, 2012, 4:26:49 AM11/8/12
to testng...@googlegroups.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?

shankar KC

unread,
Nov 8, 2012, 9:48:39 PM11/8/12
to testng...@googlegroups.com, ced...@beust.com
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
Reply all
Reply to author
Forward
0 new messages