Service test (ST) access results from the Select Data activity
Question ID: 104379
0
0

When using the Select Data activity from the Toolbox, how do I access the results of the query from the custom code? Various Step Properties are accessible via DbFetchData5 like:

DbFetchData5.Count
DbFetchData5.QueryString

But the results set is not an available property.

Marked as spam
Posted by (Questions: 3, Answers: 4)
Asked on June 30, 2011 4:29 pm
70 views
Answers (3)
1
Private answer

It is not documented, but the OutputProperties property is an XML document. It contains the result set. I'm using the Flights sample app database in these examples. Reference it like this:

XmlDocument xdoc = this.DbFetchData12.OutputProperties; // OutputProperties is an XML document
XmlNodeList rows = xdoc.SelectNodes(''//ResultTable/Row''); // Grab all of the ''Row'' elements
foreach (XmlNode row in rows) // Iterate the row elements
{
// do something with the row
var flightNumber = row.SelectSingleNode(''Flight_Number'').InnerText;
}

Or, if you want to grab a specific row, you can leverage XPath more specifically:

XmlDocument xdoc = this.DbFetchData12.OutputProperties; // OutputProperties is an XML document
XmlNode row = xdoc.SelectSingleNode(''//ResultTable/Row[Flight_Number=1124]''); // Grab row

// do something with the row
var departure = row.SelectSingleNode(''Departure'').InnerText;

Your XPath can be modified to extract the row or rows you need to process.

You will need to know what your XML result set looks like in order to build your XPath. One way to do this is to write the ResultTable element to the log, like so:

XmlDocument xdoc = this.DbFetchData12.OutputProperties; // OutputProperties is an XML document

this.Context.UserLogger.Info(xdoc.SelectSingleNode(''//ResultTable'').OuterXml);

This will display the xml document in the Output window and in the user log file. Access the user log via ST 11 menu like so:

Test -> Open Script Directory -> Log -> vtd_user.txt.

Update : An easier way to get the field names you'll need to use in your XPath is via the Property Sheet for the Select Data activity:

![alt text][1]

[1]: /upfiles/ST11ResultSetFields.PNG

Marked as spam
Posted by (Questions: 0, Answers: 1)
Answered on July 13, 2011 12:58 pm
0
Private answer

While I don't have a solution to this, may I suggest creating a database data source as an alternative.

Marked as spam
Posted by (Questions: 3, Answers: 4)
Answered on July 5, 2011 6:40 pm
0
Private answer

I'm trying to get a working example of this in place. I put a slightly modified version of wgfarm's code into the OnAfterExecuteStepEvent. It seems to be executing ok. How do I use the value of the flightnumber variable in a checkpoint?

Marked as spam
Posted by (Questions: 25, Answers: 12)
Answered on March 19, 2013 2:58 pm
EyeOnTesting

Welcome back to "EyeOnTesting" brought to you by Orasi Software, Inc.

X
Scroll to Top