3

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;
maxhb
  • 8,554
  • 9
  • 29
  • 53
arash
  • 61
  • 1
  • 6

1 Answers1

1

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();
AdrianHHH
  • 13,492
  • 16
  • 50
  • 87
  • 1
    thanks a lot AdrianHHH I do it,but didn't work.when i debug it in visual studio Context.CookieContainer.Count at first is 2 then after this.Context.CookieContainer = new System.Net.CookieContainer() is 0 but it did'nt work and show captcha yet.when i monitor request in fiddler the cookies did'nt remove – arash Feb 08 '16 at 10:02
  • How to add Cookies to the request?? – Priya Payyavula Aug 28 '17 at 18:19
  • @PriyaPayyavula That looks like a new question. Have you properly searched for answers? If you cannot find and asnwer then consider writing a new question explaining in detail what you want to do. – AdrianHHH Aug 29 '17 at 09:10