Reputation: 61
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;
Upvotes: 3
Views: 2746
Reputation: 14038
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();
Upvotes: 1