arash February 2016

Remove Cookies in Visual Studio WebTest

I want Remove Cookies of application in visual studio webtest how can i do it ? this is one of my WebTestRequest

WebTestRequest request = new WebTestRequest(
  DataProvider.Data.OnlineServer + "/Auth/Login"
);
request.Method = "POST";
request.ExpectedResponseUrl = (DataProvider.Data.OnlineServer + "/");
request.Headers.Add(
  new WebTestRequestHeader(
    "Referer",
    DataProvider.Data.OnlineServer + "/Auth/Login"
  )
);    
FormPostHttpBody request2Body = new FormPostHttpBody();
request2Body.FormPostParameters.Add("loginHash", loginHash);
request2Body.FormPostParameters.Add("username", username);
request2Body.FormPostParameters.Add("password", password);
request2Body.FormPostParameters.Add("otp", "");
request.Body = request2Body;
return request;

Answers


AdrianHHH February 2016

According to this page you can clear the cookies by creating a new CookieContainer and assigning it to the web test context. Thus overwriting the unwanted (container of) cookies with a new empty container.

In a Coded web test the code would be:

this.Context.CookieContainer = new System.Net.CookieContainer();

In a plugin the code would be:

e.WebTest.Context.CookieContainer = new System.Net.CookieContainer();

Post Status

Asked in February 2016
Viewed 2,327 times
Voted 12
Answered 1 times

Search




Leave an answer