In my WebTest, I wanted the 1st two WebRequests to bypass the proxy and the 3rd one to use a Proxy. Here I found it useful to create a WebTestRequestPlugin that is later associated with a WebRequest to set a proxy in the PreRequest method.
Here is the code for the WebTestRequestPlugin.
public class ProxySetter : WebTestRequestPlugin
{
string proxy = null;
public string Proxy
{
get
{
return this.proxy;
}
set
{
this.proxy = value;
}
}
public override void PreRequest(object sender, PreRequestEventArgs e)
{
if (!String.IsNullOrEmpty(this.proxy))
{
e.WebTest.Proxy = this.proxy;
}
else
{
e.WebTest.Proxy = null;
}
}
}
No comments:
Post a Comment