I want to modify the request of my UFT API HTTP Activity programatically, how do I do that?
Question ID: 106884
0
0

My request to my web service is done in an HTTP Activity in UFT-API script. I am loading a JSON file for the body of the request and I need to programatically set a value of a particular node on the fly (based on a previously returned value, but that part is irrelevant). How do I identify the element, modify it, and make the request use my modified body. I guess I need to do it in an the before execute event of the activity, but how do I code it?

Marked as spam
Posted by (Questions: 36, Answers: 3)
Asked on May 25, 2016 3:08 pm
411 views
Answers (1)
0
Private answer

Typical XML parsing and modification like this example:

public void HTTPActivity8_OnBeforeExecuteStepEvent(object sender, STActivityBaseEventArgs args)
{

string strMyXml= this.HTTPActivity8.XMLBody.InnerXml;

// load the XML from the activity
XmlDocument d = new XmlDocument();
d.LoadXml(strMyXml);

//identify and modify the specific element identified as ''model'' in my example
XmlNode root = d.DocumentElement;
XmlNode myNode=root.SelectSingleNode(''model'');

// plug in your value
myNode.InnerXml=''MY MDIFIED VALUE GOES HERE'';

// then save the modifications back to the activities XML
this.HTTPActivity8.XMLBody.InnerXml=d.InnerXml;

}

Marked as spam
Posted by (Questions: 6, Answers: 167)
Answered on May 25, 2016 3:10 pm
EyeOnTesting

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

X
Scroll to Top