Issue:
I have a junk request as dependent of dependent request in
my web test. I need to delete that junk request.
Solution:
If it is dependent request then deleting is pretty much easy
but to delete dependent request of dependent request is little bit difficult.
Below code wettestrequest plug in will help you to do that
task.
public class Removedepdep : WebTestRequestPlugin
{
string m_startsWith;
public string FilterDependentRequestURL
{
get { return m_startsWith; }
set { m_startsWith = value; }
}
public override void PostRequest(object sender, PostRequestEventArgs e)
{
WebTestRequestCollection depsToRemove = new WebTestRequestCollection();
// Note : you can't modify the collection inside a foreach, hence the second collection requests to remove.
foreach (WebTestRequest r in e.Request.DependentRequests)
{
if (!string.IsNullOrEmpty(FilterDependentRequestsThatStartWith) &&
r.Url.StartsWith(FilterDependentRequestsThatStartWith))
{
depsToRemove.Add(r);
}
}
foreach (WebTestRequest r in depsToRemove)
{
e.Request.DependentRequests.Remove(r);
}
}
}