Data files

The Storefront Test Automation Engine includes a sample mechanism to load values from XML data files. Having separate data files lets developers isolate the logic of their tests from the data they are testing. It also makes it possible to reuse a test case by using multiple sets of data.

Note: You do not have to use the data file mechanism; there are many ways to load data in a test.

Use of data files

The data files can be accessed within a test case that has the following field and annotation defined:
//A Variable to retrieve data from the data file.
	@DataProvider
	private final WteDataProvider dsm;
The Web Test Engine automatically defines the data file based on the class name, and specifies the test and data block. The xml data file can be read by using the following sequence of calls:
// fetch the SHARED_1 environment parameter, should match "value 1"
String envShared1 = dsm.getEnvParameter("SHARED_1");
// fetch the PARAMETER_1 input parameter from TEST_1 - BLOCK_1, should match "value 1.1"
String inputParameter = dsm.getInputParameter("PARAMETER_1");
		
// fetch the PARAMETER_1 output parameter from TEST_1 - BLOCK_1, should match "value 3.1"
String outputParameter = dsm.getOutputParameter("PARAMETER_1");

Data file structure

An XML data file contains the following nodes:
  • <Scenario> node: The root node of the XML document; it contains a single <Env> node and one or more <Test> nodes.
  • <Env> node: Contains parameters that are shared across all tests and data blocks. It contains a list of <Parameter> nodes.
  • <Test> nodes: Represent the data that is associated with a test case. The test nodes must contain a unique name in the data file. The <Test> nodes contain a list of <Datablock> nodes.
  • <Datablock> nodes: Contains the data that is associated with a part of a test case. The name of a data block must be unique within a <Test> node. <Datablock> nodes contain one <Input> node and one <Output> node.
  • <Input> node: Contains a list of <Parameter> nodes that are associated with the inputs required to perform a test case.
  • <Output> node: Contains a list of <Parameter> nodes that are associated with the outputs produced by a test case.
  • <Parameter> node: Contains a parameter that is required for a test. <Parameter> nodes must contain a unique name within their group and a value.
<?xml version="1.0" encoding="UTF-8"?>
<Scenario name="SCENARIO_NAME">
  <Env>
    <Parameter name="SHARED_1" value="value 1" />
    <Parameter name="SHARED_2" value="value 2" />
  </Env>
    <Test name="TEST_1">
      <Datablock name="BLOCK_1">
	  <Input>
	    <Parameter name="PARAMETER_1" value="value 1.1" />
	    <Parameter name="PARAMETER_2" value="value 2.1" />
	  </Input>
	  <Output>
	    <Parameter name="PARAMETER_1" value="value 3.1" />
	    <Parameter name="PARAMETER_2" value="value 4.1" />
	  </Output>
	</Datablock>
	<Datablock name="BLOCK_2">
	  <Input>
	    <Parameter name="PARAMETER_1" value="value 1.2" />
	    <Parameter name="PARAMETER_2" value="value 2.2" />
	  </Input>
	  <Output>
	    <Parameter name="PARAMETER_1" value="value 3.2" />
	    <Parameter name="PARAMETER_2" value="value 4.2" />
	  </Output>
	</Datablock>
    </Test>
    <Test name="TEST_2">
	<Datablock name="BLOCK_1">
	  <Input>
	    <Parameter name="PARAMETER_1" value="value 1.3" />
	    <Parameter name="PARAMETER_2" value="value 2.3" />
	  </Input>
	</Datablock>
    </Test>
</Scenario>