Form post parameters can be accessed in a web test recorder plugin via the body field of a web request, but the body needs to be cast to the correct type. A recorder plugin provides has the recorded web test as a (field of a) parameter, the Items
of the test include the individual requests. They also include comments and so on. An Item
that is a WebTestRequest
may have a Body
field that, after casting, provides the form post parameters. This code shows a plugin that displays some details of the form post parameters via a WriteLine
method that is not shown here. The inner loop can be replaced with code to modify, or delete or add new form post parameters.
public override void PostWebTestRecording(object sender, PostWebTestRecordingEventArgs e)
{
foreach (WebTestItem wti in e.RecordedWebTest.Items)
{
WebTestRequest wtiwtr = wti as WebTestRequest;
if (wtiwtr != null)
{
FormPostHttpBody formBody = wtiwtr.Body as FormPostHttpBody;
if (formBody == null)
{
// no formBody.
}
else
{
WriteLine("Have {0} form post parameters", formBody.FormPostParameters.Count);
foreach (FormPostParameter fpp in formBody.FormPostParameters)
{
WriteLine("FPP '{0}' = '{1}'", fpp.Name, fpp.Value);
}
}
}
}
}
Several other parts of the recorded web test can be accessed via these casts of wti
in the code.
Comment wtic = wti as Comment;
IncludedWebTest wtiiwt = wti as IncludedWebTest;
SharepointInformation wtispi = wti as SharepointInformation;
TransactionTimer wtitt = wti as TransactionTimer;
WebTestConditionalConstruct wtiwtcc = wti as WebTestConditionalConstruct;