Transcripted Summary

# The TestNG XML file

The purpose of a TestNG XML file is to store data and to carry data for all of our testing. Here's an XML file for our test suite.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Test Automation University Suite">
  <test name="configuration annotation Test">
    <classes>
      <class name="com.testautomationu.chp3annotations.Configuration_Annotations">
      	<methods>
      		<include name = "searchCustomer"/>
      		<include name = "searchProduct"/>
      	</methods>
      </class>
    </classes>
  </test> <!-- configuration annotation Test -->
</suite> <!-- Test Automation University Suite -->


In this example, we see the following tags:

  • <suite>
  • <test>
  • <class>
  • <methods>

A <suite> can have one or more tests.

A <test> can have one or more classes.

A <class> can have one or more methods.

The XML file gives us a picture on why the annotations execute in a particular order.

If we run our test suite, we see the same output as before. It’s the same output because this execution has one <test> tag.

Chrome – Set Up System Property

Open Chrome

Open Test Application

Sign In

Search For Customer

Sign Out

Sign In

Search For Product

Sign Out

Close Test Application

Close Chrome

Clean Up All Cookies

Let’s look at an XML file that has two <test> tags:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd">
<suite name="Test Automation University Suite">
  <test name="Search For A Customer">
    <classes>
      <class name="com.testautomationu.chp3annotations.Configuration_Annotations">
      	<methods>
      		<include name = "searchCustomer"/>
      	</methods>
      </class>
    </classes>
  </test> <!-- configuration annotation Test -->
  
   <test name="Search For A Product">
    <classes>
      <class name="com.testautomationu.chp3annotations.Configuration_Annotations">
      	<methods>
      		<include name = "searchProduct"/>
      	</methods>
      </class>
    </classes>
  </test> <!-- configuration annotation Test -->
</suite> <!-- Test Automation University Suite -->

This XML file does not include the test methods together. We see the first test name is Search For A Customer and the second test name is Search For A Product.

After running this, we can see that the output is different than before.

Chrome – Set Up System Property

Open Chrome

Open Test Application

Sign In

Search For Customer

Sign Out

Close Test Application

Close Chrome

Open Chrome

Open Test Application

Sign In

Search For Product

Sign Out

Close Test Application

Close Chrome

Clean Up All Cookies

This time our execution does not immediately sign back into the application after signing out of the application. Now, the execution processes @AfterClass (Close Test Application) and @AfterTest (Close Chrome) after signing out. Why? Because in the XML file, the test methods are not included the same <class> tag. Therefore, execution will not sign back in to start our next test.

Notice, Chrome is still set up after executing @BeforeSuite. That means the @AfterSuite annotation is the only annotation that has not been executed after the first test. It is only executed after both tests have completed.

In reality, we probably would not use four Before configuration annotations and four After configuration annotations. However, I wanted you to see how the XML file is connected to the annotations and how the XML file allows us to execute the same methods for one test compared to more than one test.



Resources



© 2024 Applitools. All rights reserved. Terms and Conditions Privacy Policy GDPR