Skip to content

How to read data from an Xml file (stored in Files module) from within my test run



In this example you will see how you can read data from a Xml and use the data within your run. For this example, following Xml data will be used as reference and the same is expected in the file available in the "Files" module

	
<?xml version="1.0" encoding="UTF-8"?>
<BookDetails>
	<Book ISBN_10="1951028023">
		<Genre>Self-Help</Genre>
		<Search_Qualifier_Product_Department>Books</Search_Qualifier_Product_Department>
		<Search_Keyword_For_Product>I AM A LEADER</Search_Keyword_For_Product>
		<Product_Title>I AM A LEADER: A 90-Day Leadership Journal for Kids</Product_Title>		
		<Author>Peter J. Liang</Author>
		<Publisher edition="Kindle">Absolute Author Publishing House</Publisher>
		<Language>English</Language>
	</Book>
	<Book ISBN_10="0689711999">
		<Genre>Biography</Genre>
		<Search_Qualifier_Product_Department>Books</Search_Qualifier_Product_Department>
		<Search_Keyword_For_Product>alexander books</Search_Keyword_For_Product>
		<Product_Title>Alexander, Who Used to Be Rich Last Sunday</Product_Title>		
		<Author>Judith Viorst</Author>
		<Publisher edition="PaperBack">SILVER BURDETT (August 30, 1987)</Publisher>
		<Language>English</Language>
	</Book>
</BookDetails>

In the test run following details from the Xml are required and need to be parsed.

  • ISBN_10
  • searchKeywordForProduct
  • author
  • publisher
  • edition

Worksoft SaaS supports reading data from a Xml file to a dataset. Hence a dataset would be initialised with data definition that has same attributes. Once the data is loaded to dataset using command "ddCreateDataSetFromXmlFile" regular array commands can be used for getting values from the dataset.

# Command Target Value
Creating the dataset and specifying the data definition name of the data file
1 ddCreateDataSet dsBookDetails BookJson(W)
Reading the data from the Json file into the dataset
2 ddCreateDataSetFromXmlFile BookDetails.json dsBookDetails
Print number of rows persisted to dataset
3 ddGetRowCount dsBookDetails count
4 echo ${count}

Tips, Tricks, Gotchas & Best Practices: 


Feedback and Knowledge Base