Highlighted
Phil3232 Frequent Contributor.
Frequent Contributor.
111 views

API Testing Parameter Strings

Jump to solution

I am using UFT version 12.02 and automating APIs. The way in which the schema has been constructed means that most of the data (other than user credentials) are encoded into a single element. Within that element is xml with the bulk of elements. When i create my request i can successfully run the test if i have 'hardcoded' the data into that element i.e. i place the full string of the element which will contain the usual encoding header info then the elements:

<Version>1</Version><CSPId>5480</CSPId>

However, If i try to add a parameter into my expression from another step e.g. retrieving data from the database then it always fails as it think the XML is invalid.

<Version>1</Version><CSPId>{Step.OutputProperties.DbFetchData8.ResultTable.Row[1].USERNAME}</CSPId>

Does anyone know how i can pass in a parameter so it works? i have tried to use replace string to replace the data with the parameter and then use the results of the replace to insert the whole encoded xml into the holding element but it still doesnt work. 

Tags (4)
0 Likes
1 Solution

Accepted Solutions
Phil3232 Frequent Contributor.
Frequent Contributor.

Re: API Testing Parameter Strings

Jump to solution
I have found a way around this now where i use a 'replace string' activity to place the ID from the 'Select Data' activity result into the string being passed into the request.

Surely there must be a simpler way to do this though. It must be that the element does not parse correctly when a parameter is inserted in what it thinks is XML but should actually be read as a string. I have tried using CDATA for this too but UFT does not like that in the expression.
0 Likes
5 Replies
Micro Focus Contributor
Micro Focus Contributor

Re: API Testing Parameter Strings

Jump to solution

Hi Phil3232,

Does the select data step run successfully? Could you provide more information about your test scenarios? 

What activity in your test use the result of Select Data method? And what parameter in the activity input properties need this link value such as "<Version>1</Version><CSPId>{Step.OutputProperties.DbFetchData8.ResultTable.Row[1].USERNAME}</CSPId>"?

Maybe you can find some error info in the HP.UFT.log. That will help.

Thanks,

Wen-Wen.Wang

0 Likes
Phil3232 Frequent Contributor.
Frequent Contributor.

Re: API Testing Parameter Strings

Jump to solution

Hi,

Sorry for the late reply. The select data step does run correctly but it is when the result of that query goes in to the API method.

The way the API has been written is not usual in that we have the Echo Token, username and Password in the body which is normal but then we have another element which contains XML for the details of the request.

All i am doing is putting the correct xml in the expression and replacing the hardcoded ID with the result parameter. I can even see in the results the the correct Request is being sent and using the ID from the parameter but it errors on the response.

The checkpoint in the results has the following detail:

"Trying to get XmlNode for Xpath: /*[local-name(.)='Envelope'][1], XmlNode was null"

Phil

0 Likes
Phil3232 Frequent Contributor.
Frequent Contributor.

Re: API Testing Parameter Strings

Jump to solution

Further to my last response if looks like that when UFT is sending the response, when the ID is not hardcoded it is reading the element as XML but when it is hardcoded it is reading it as a string as shown below. When it is being sent as a string then it works but i dont know how to force it to do that.

USING PARAMETER:
<Body>

<echotoken>Dummy</echotoken>
<username>Test</username>
<password>Test</password>
11813520
</GetProspectInterestSummary>
</Body>
</Envelope>

 

USING HARD CODED ID
<Body>

<echotoken>Dummy</echotoken>
<username>Test</username>
<password>Test</password>
<?xml version="1.0" encoding="utf-16"?><GetProspectInterestSummaryParametersV1 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><Version>1</Version><ProspectDetailId>1813520</ProspectDetailId></GetProspectInterestSummaryParametersV1>
</GetProspectInterestSummary>
</Body>
</Envelope>

0 Likes
Phil3232 Frequent Contributor.
Frequent Contributor.

Re: API Testing Parameter Strings

Jump to solution
I have found a way around this now where i use a 'replace string' activity to place the ID from the 'Select Data' activity result into the string being passed into the request.

Surely there must be a simpler way to do this though. It must be that the element does not parse correctly when a parameter is inserted in what it thinks is XML but should actually be read as a string. I have tried using CDATA for this too but UFT does not like that in the expression.
0 Likes
Micro Focus Contributor
Micro Focus Contributor

Re: API Testing Parameter Strings

Jump to solution

Hi Phil,

It seems that UFT loses some elements of the xml which came from the SelectData activity from your description. As you did, adding a converter can be a work around to make the request use the correct value.

And the reason why this error happens, it is still a little bit confusing. If you need a further investigation from the dev, maybe you can open a CPE case to handle this problem. 

BR,

Wenwen

The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.