Tuesday, October 4, 2016

TestNG Selenium - Create Test Suites





In TestNG framework, we need to create testng.xml file to create and handle multiple test classes. This is the xml file where you will configure your test run, set test dependency, include or exclude any test, method, class or package and set priority etc.

Step 1 : Create a TestNG XML
1) Right click on Project folder, go to New and select ‘File‘ as shown in below image.


2) In New file wizard, add file name = ‘testng.xml‘ as shown in below given image and click on Finish button
 

3) It will add testng.xml file under your project folder.

After giving appropriate names, now your testng.xml file will looks like this:

<suite name = "Test - Suite">
    <test name="website QA">
        <classes>
            <class name="automationFramework.TestNG" />
        </classes>
    </test>
</suite>



 
Very first tag is the Suite tag<suite>, under that it is the Test tag<test> and then the Class tag<classes>. You can give any name to the suite and the test but you need to provide the correct name to the <classes> tag which is a combination of your Package name and Test Case name.

When you run testng.xml, it  will execute only those tests, which are mentioned in the testng.xml. The rest of the test cases under ‘automationFramework’ package will remain untouched.

No comments:

Post a Comment