Create testNG.xml programmatically and store it

1,202 views
Skip to first unread message

Shaik

unread,
Jun 11, 2014, 12:02:47 PM6/11/14
to testng...@googlegroups.com
Hello..

I have an requirement where i have to create the individual suite xml files and then map these individual files into testNG.xml.

I am able to achive the individual xml file creation ,but unable to map these individual suite xml into testng.xml


Note:- i donot want to run (testng.run) , but want to save it.

List files=new ArrayList();
files.add("C:\\MasterData.xml");
XmlSuite suite = new XmlSuite();
suite.setSuiteFiles(files);
List<XmlSuite> suites = new ArrayList<XmlSuite>();
suites.add(suite);

Any suggestion will be appreciated.

Thanks
Shaik

Krishnan Mahadevan

unread,
Jun 14, 2014, 1:01:05 AM6/14/14
to testng...@googlegroups.com
You need something like this :

package org.rationale.emotions.testng;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import org.testng.xml.XmlSuite;

public class SuiteFileCreator {

    public static void main(String[] args) throws IOException {
        XmlSuite suite = new XmlSuite();
        suite.setName("Master suite");
        List<String> files = new ArrayList<String>();
        files.add("/Users/krmahadevan/githome/test-projects/ExperimentsWithWebDriverAndTestNG/demo-testng.xml");
        files.add("/Users/krmahadevan/githome/test-projects/ExperimentsWithWebDriverAndTestNG/master-testng-enum.xml");
        suite.setSuiteFiles(files );
        System.out.println(suite.toXml());
        FileWriter writer = new FileWriter(new File("MyMasterSuite.xml"));
        writer.write(suite.toXml());
        writer.flush();
        writer.close();
        System.out.println(new File("MyMasterSuite.xml").getAbsolutePath());
    }
}


krmahadevan@CastleGreySkull ~/githome/test-projects/ExperimentsWithWebDriverAndTestNG  $ cat MyMasterSuite.xml 
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Master suite">
  <suite-files>
    <suite-file path="/Users/krmahadevan/githome/test-projects/ExperimentsWithWebDriverAndTestNG/demo-testng.xml"/>
    <suite-file path="/Users/krmahadevan/githome/test-projects/ExperimentsWithWebDriverAndTestNG/master-testng-enum.xml"/>
  </suite-files>
</suite> <!-- Master suite -->
krmahadevan@CastleGreySkull ~/githome/test-projects/ExperimentsWithWebDriverAndTestNG  $ 

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

Reply all
Reply to author
Forward
0 new messages