Highlighted
New Member.
5645 views

UFT API Test - REST - Assign JSON request run time

Jump to solution

Hello all,

 

I need to assign the JSON file from my local folder path dynamically for the REST API call. I handled using Load JSON option available in the REST Call but I need to do it programmatically using the custom code option UFT provided with C# Event Handlers.

 

If any one have some help docs or a place I can refer regarding these C# custom methods for the UFT API, please point to me.

Accept as solution/Give Kudos to the author if the piece of information answered/helped you to solve your problem.
All the thoughts here are mine not related to my employer nor anyone.
Test Automation Ecstasy
0 Likes
1 Solution

Accepted Solutions
Highlighted
New Member.

Thanks RajKumar for your suggestion.

 

I did it simply by modifying the content type as File and linked to input parameter.

Accept as solution/Give Kudos to the author if the piece of information answered/helped you to solve your problem.
All the thoughts here are mine not related to my employer nor anyone.
Test Automation Ecstasy

View solution in original post

0 Likes
6 Replies
Highlighted
Outstanding Contributor.
Outstanding Contributor.

Create a default Handler for the BeforeExecuteStepEvent.  TestUserCode.cs file will be opened with the template as below.

 

public void <YourActivityStepID>_OnBeforeExecuteStepEvent(object sender, STActivityBaseEventArgs args)
     {

            //TODO: Add your code here...
            
     }

 

Insert this line of code after the //TODO statement & replace the StepID from your Step.

 

this.<YourActivityStepID>.JsonContent.Load("C:\\TestData\\JSON.json");

_____________________
Rajkumar Rajangam
0 Likes
Highlighted
New Member.

 

this.<YourActivityStepID>.JsonContent.Load("C:\\TestData\\JSON.json");


Exactly this is the method I am looking for. But for me It's not listing this method. Could you post the steps you used to create API test for REST service.

 

I am getting TextBody but assigning the string to TextBody not working.

Accept as solution/Give Kudos to the author if the piece of information answered/helped you to solve your problem.
All the thoughts here are mine not related to my employer nor anyone.
Test Automation Ecstasy
0 Likes
Highlighted
Outstanding Contributor.
Outstanding Contributor.

Which activity did you use? JsonToString?

 

Make sure there are no errors in the Test, otherwise, it won't compile & intelli-sense doesn't work. You won't get the context sentive methods that you are looking for.

_____________________
Rajkumar Rajangam
0 Likes
Highlighted
New Member.

Thanks RajKumar for your suggestion.

 

I did it simply by modifying the content type as File and linked to input parameter.

Accept as solution/Give Kudos to the author if the piece of information answered/helped you to solve your problem.
All the thoughts here are mine not related to my employer nor anyone.
Test Automation Ecstasy

View solution in original post

0 Likes
Highlighted
Absent Member.
Absent Member.

Hi,

I am also facing the same issue. I want to load JSON file runtime using C# custom code in UFT

Please share solution or any sample code.

 

Thanks,

-Nitin

0 Likes
Highlighted
Absent Member.
Absent Member.

 

0 Likes
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.