UFT API -- "Select data" How to return values for query to Sybase database - hp-uft

I have to validate an API output with a values stored in Sybase DB.
When I use "select Data" activity to fetch the value from Sybase table, the value is returned in XML format as below:
<Row>
<ColumnName1> Value </ColumnName1>
<ColumnName2> Value </ColumnName2>
<ColumnName3> Value </ColumnName3>
</Row>
However I need only the Value so I can save it in excel to compare in my next step. Comparison is being done on value basis not with xml. I need to convert the response from select data (which is in XML format shown above) .
The subsequent checkpoint in API output fails as I need to provide individual values as input to the service.
I will need a solution that can either split array and give me individual values at run time Or I should be able to save values in Excel which I can save and import at run time.

You can use the COM object for Microsoft's XML Parser. Something like this should do it,
set objXml = CreateObject("Microsoft.XMLDOM")
objXml.Load("C:\yourxmlpath.xml")
' Get your node (you can traverse it like a path)
set allMathchingRows = objXml.selectNodes("/Row")
For intRow = 0 To allMathchingRows.Length - 1
For each Node in allMathchingRows(intRow).ChildNodes
strAllRowData = strAllRowData + "," + Node.text
Next
' Remove the ' appended to the start of string
strAllRowData = Right(strAllRowData, Len(strAllRowData) - 1)
Next
you may want to refine it more if you want your data separate for each rows

Related

How to display the text from XMLTYPE Column including the spaces using oracle query

I have XML Data type column with the below data in it, and i want to extract the data from below XML including the spaces between the tags. after there is one space like that after math_expression also there is one space.
when i used Extract function to extract the data from the below XML it is eliminating the spaces.
Example XMLTYPE Data column:
<quantity_a> <math_expression> <math display="inline" overflow="scroll"> <mrow> <mn>3</mn> <mi>x</mi> <mo>+</mo> <mn>2</mn>
</mrow> </math> </math_expression> </quantity_a>
Output i Want is:
" 3 X + 2 "
Appreciate your help on this.
String-join - description
/quantity_a/math_expression/math/mrow/* - it returs all elements from mrow node.
select xmlquery('string-join( /quantity_a/math_expression/math/mrow/*/text()," ")' passing xmltype('<quantity_a>
<math_expression>
<math display="inline" overflow="scroll">
<mrow> <mn>3</mn> <mi>x</mi> <mo>+</mo> <mn>2</mn>
</mrow> </math> </math_expression> </quantity_a>') returning content ) from dual;

XPath2: A sequence of more than one item is not allowed as the first argument of string()

I have this xml that contains certificates and its attributes. Here is the xml over which I am running the extraction query
<Certificates>
<CertificateAndChain>
<Certificate>
<FriendlyName />
<Thumbprint>EE8B375347FCADDC25547FDDF61866E07D5B6A71</Thumbprint>
<SerialNumber>256BB11DB5BE889E46EBCD85608DA849</SerialNumber>
<Version>3</Version>
<SignatureAlgorithm>sha1RSA</SignatureAlgorithm>
<Issuer>CN=certname</Issuer>
<Subject>CN=certname</Subject>
<NotAfter>2040-09-26T18:30:00Z</NotAfter>
<NotBefore>2016-09-27T18:30:00Z</NotBefore>
<IsVerified>false</IsVerified>
</Certificate>
.
.
.(continued)...
I have written another test over this xml that needs to extract thumbprints of all the certificates that are about to get expired in next 10 days.
As part of the test, , I have written the Extraction query as:
<XPath2ResponseParameter Name="TPName"><ExtractionQuery><![CDATA[string(//CertificateAndChain/Certificate[NotAfter[text() <= (current-dateTime() + xs:dayTimeDuration('P10D'))]]/Thumbprint)]]></ExtractionQuery></XPath2ResponseParameter>
The test is in xml file as well. However, when I run the test, I get this exception:
A sequence of more than one item is not allowed as the first argument of string().
This is probably happening because there are multiple certificate elements present in the xml. So, I couldn't figure out the way to extract all the thumbprints failing the mentioned condition(there could be more than 1 and I need to extract all of them)
Can anyone help me fix this?
You can invoke function in axis when using XPath 2.0. So, try to move string() function to the end of the inner XPath (formatted for readability) :
//CertificateAndChain
/Certificate[
NotAfter[
text() <= (current-dateTime() + xs:dayTimeDuration('P10D'))
]
]/Thumbprint
/string()
UPDATE :
Since CDATA can't receive multiple strings in this context, according to the error message in your first comment, then you need to combine those strings into one, presumably using string-join() :
string-join(
//CertificateAndChain
/Certificate[
NotAfter[
text() <= (current-dateTime() + xs:dayTimeDuration('P10D'))
]
]/Thumbprint
/string()
,' ')

Store Variable value from server to client

I am using this code to connect to server.
'Client-Side Connect Code
sockMain.RemoteHost = 192.168.1.125
sockMain.RemotePort = 12345
sockMain.Connect
'Server Side code to send message to client
sockMain.SendData txtSend.text
Now, if i write :: a="127" , and send it to client from server, then this message will be displayed in textbox on client side , now how can i use this message , a="127" to store variable value ?
You cannot literally create a new named variable within a compiled VB6 application at runtime in the manner described. You can, however, certainly extract the numeric portion of the value in the textbox and assign that value to a local variable in the application.
If you want to capture the numeric portion of the value in the textbox, and you know the text format will always be of the form "a=somenumber," you can strip off the first two characters to eliminate the "a=" portion, and then use the VB `Val' function on the remaining string to capture the numeric value:
' Generalized example for pulling integer portion from
' a textbox of the form 'a=12345'; amend as appropriate. Untested.
Dim a as integer
Dim receivedData as String
' Assuming txtBox1 as the name of the textbox in the client
receivedData = txtBox1.Text
receievedData = mid$(value,3)
a = Val(receivedData)
`

Compare two xml files using VBS in QTP

I need to compare 2 xml files using QTP where the values for each tag needs to be compared and need to print the difference in values if found. I used the built in Function XMLUTIL but its not working as expected i.e.. its creates a file with differences including the parent tag.
<tns:AAL_Request_NEW xsi:schemaLocation="http://www.bnymellon.com/AAL_Request_NEW AAL_Request_NEW.xsd">
<tns:OPF_Information>
<tns:Source>
<tns:Source>EPH</tns:Source>
</tns:Source>
<tns:References>
<tns:Accounting_Record_Reference>130830000672401</tns:Accounting_Record_Reference>
<tns:OPF_Reference>EPH1308300006724</tns:OPF_Reference>
<tns:Group_Reference>EPH1308300006723</tns:Group_Reference>
</tns:References>
</tns:OPF_Information>
</tns:AAL_Request_NEW>
In the above xml file i just need the tags with values like
tns:Source with value EPH, tns:Accounting_Record_Reference with value 130830000672401, tns:OPF_Reference with value EPH1308300006724 and tns:Group_Reference EPH1308300006723 to be compared and not the parent tags like tns:References, tns:OPF_Information or tns:AAL_Request_NEW.
Can anyone help with the logic to fetch the tags which has no child tag inside it and ends immediately with having only a value between its start <> and end and compare it with the other file and print the tag name and the values if there is a difference?
you can use CreateObject("Microsoft.XMLDOM") to read the xml files and retrive the tags by tag name and comparte them both.
Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("<XML PATH>")
Set Root = objXMLDoc.documentElement
Set tags = root.tagnames
Set NodeList = Root.getElementsByTagname("<node name>")
For Each Elem In NodeList
msgbox Elem.text
Next
Thanks and regards

How to use "Result Variable Name" in JDBC Request object of Jmeter

In JMeter I added the configuration for oracle server. Then I added a JDBC request object and put the ResultSet variable name to status.
The test executes fine and result is displayed in treeview listener.
I want to use the variable status and compare it with string but jmeter is throwing error about casting arraylist to string.
How to retrieve this variable and compare with string in While Controller?
Just used some time to figure this out and think the accepted answer is slightly incorrect as the JDBC request sampler has two types of result variables.
The ones you specify in the Variable names box map to individual columns returned by your query and these you can access by saying columnVariable_{index}.
The one you specify in the Result variable name contains the entire result set and in practice this is a list of maps to values. The above syntax will obviously not work in this case.
The ResultSet variable returned with JDBC request in JMeter are in the for of array. So if you want to use variable status, you will have to use it with index. If you want to use the first(or only) record user status_1. So you need to use it like status_{index}.
String host = vars.getObject("status").get(0).get("option_value");
print(host);
log.info("----- " + host);
Form complete infromation read the "yellow box" in this link:
http://jmeter.apache.org/usermanual/component_reference.html#JDBC_Request
Other util example:
http://jmeter.apache.org/usermanual/build-db-test-plan.html
You can use Beanshell/Groovy (same code works) in JSR233 PostProcessor to work with “Result Variable Name” from JDBC Request like this:
ArrayList results = vars.getObject("status");
for (HashMap row: results){
Iterator it = row.entrySet().iterator();
while (it.hasNext()){
Map.Entry pair = (Map.Entry)it.next();
log.info(pair.getKey() + "=" + pair.getValue());
}
}
Instead of output to log replace with adding to string with delimiters of your choice.

Resources