How to Run the test suite using testng.xml file?

In our previous example, we have written three test cases in one class file. But in real, we wont do like that. Multiple class files will be there to test. So the best and easy way to run these multiple classes is to have a xml file to run all those classes. Let's explore how to do that in this chapter.

To achieve this, let's take all the classes we have written so far for the TestNG section. If you have followed my example, you should have three classes as shown below.

Steps to follow:

  • Create a testng.xml file.

  • Paste the below code in that if you have exactly followed my examples. If you have given some other names, change it accordingly.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
<suite name="Test Suite" verbose="2">
    <test name="Run multiple tests">
        <classes>
        <class name="seleniumWithTestNG.OpenGoogle"/>
        <class name="seleniumWithTestNG.SkipTest"/>
        <class name="seleniumWithTestNG.TestWithPriority"/>
        </classes>
    </test>
</suite>
  • If you had followed the steps properly, you will have a testng.xml file in your project, right click on that and run as testng suite.

Output: Your output may vary based on your code.

PASSED: openGoogle
PASSED: wearSeatBelt
PASSED: startEngine
PASSED: startEngine
PASSED: putFirstGear
PASSED: putSecondGear
PASSED: putFirstGear
PASSED: putThirdGear
PASSED: putSecondGear
PASSED: putThirdGear

===============================================
    Run multiple tests
    Tests run: 10, Failures: 0, Skips: 0
===============================================

1498998172595    Marionette    INFO    New connections will no longer be accepted
21.931 seconds

===============================================
Test Suite
Total tests run: 10, Failures: 0, Skips: 0
===============================================

Do you remember me saying reporting facilities of TestNG. The above mentioned thing is just a console report. Prepare to be amazed by the level of reporting provided by TestNG in the next chapter.

results matching ""

    No results matching ""