简体   繁体   中英

How can i run a Test multiple times using testNG using XML file?

I've 3 @Test methods say, methodA, methodB and methodC. All the 3 methods are used to fill a Form one by one that takes input from CSV file. My XML file looks like below...

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Fill Forms">
    <test name="Fill multiple times">
        <classes>
            <class name="com.class"/>
                <methods>
                    <include name='methodA'/>
                    <include name='methodB'/>
                    <include name='methodC'/>
                </methods>
            </class>
        </classes>
    </test>
</suite>

I want to run the Test 'Fill Multiple Times' multiple times.

Kindly suggest me an idea...

If each method is interacting with the same elements and just passing different inputs, try parameterizing your tests with one of the approaches available in TestNG.

http://testng.org/doc/documentation-main.html#parameters

XML Parameters will work well, but this will result in a more verbose Suite XML file.

My recommendation, assuming the above condition is true, would be to use a DataProvider with your test. This way, you only need to write the test method once and the DataProvider will iterate over the test for each data set you define.

EDIT: Since your test isn't able to be parameterized... If you're simply looking to repeat the test methods a number of times, you could either repeat the <test> node on the XML as many times as you wish to repeat the execution. If you wish to keep your XML from getting too verbose, you could look into creating a test case factory .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM