How to convert testingSuit xml file to a java class

262 views Asked by At

I have testingSuit.xml which is interlinked to many xml files to test many test cases. Now I would like to run that testingSuit.xml (which is interlinked) through Java class programmatically. Here is my sample code

<suite name="masterSuite" enabled="true" preserve-order="true">
 <suite-files>
    <suite-file path="src/test/resources/TestSuite1.xml" />
 </suite-files>
</suite>

And another xml files

<suite name="TestSuite1" parallel="tests" thread-count="2">
 <suite-files >
    <suite-file path="src/test/resources/TestSuite2.xml"/>  
 </suite-files>
</suite>

And another xml file is

<suite name="TestSuite2">
<test name="testName1">
    <classes>           
        <parameter name="propertiesFile" value="p1.properties" />
        <parameter name="datasetFile" value="src/test/resources/dataFiles/dataset1.json" />
        <parameter name="size" value="2048" />
        <class name="Test1">
            <methods>
                <include name="testMethod" />
            </methods>
        </class>
    </classes>
</test>

Converted this to Java class like this

public static void main(String[] args) {
    List<String> files=new ArrayList<String>();
    files.add("src/test/resources/TestSuite1.xml");
    XmlSuite suite = new XmlSuite();
    suite.setSuiteFiles(files);
    List<XmlSuite> suites = new ArrayList<XmlSuite>();
    suites.add(suite);
    TestNG tng = new TestNG();
    tng.setXmlSuites(suites);
    tng.run();
}

But not working, Can anyone please guide me the way for this?

0

There are 0 answers