How to clear Cookies in a visual studio Webtest cookie container
Clearing cookies from VSTS requests
In VSTS, the webtest cookies are not reset unless the webtests finishes, so the cookie container retains the values until the end of the webtest. In such a case if you want to have multiple users signing in and signing out using loops within a webtest, the new users ends up using cookies from earlier users, and may lead to unexpected behaviours in the test.
In order to avoid a situation like above, you would need to clear the cookie container of the webtest using plugins. Below is an example:-
public class ClearCookies : WebTestRequestPlugin
public override void PostRequest(object sender, PostRequestEventArgs e)
e.WebTest.Context.CookieContainer = new System.Net.CookieContainer();
Comments are closed.