Removing cookies from subsequent requests

Dec 6, 2009 at 11:14 PM

Hello,

We are developing a web application to profile mobile device/browser capabilities. One of the capabilities being profiled is a cookie support by a mobile browser. Web app basically sets couple of cookies and then checks in the next request whether those cookies are there.

We are using VSTT to test the web application and I was having problems with writing a web test to test one of the scenarios.

The scenario I wanted to test is when the client browser does not support cookies. This means that the subsequent request should not contain cookies that web app returns in the first response. The problem is that VSTT web test automatically sends all the cookies from previous response in the next request. Both WebTestRequest.Cookies and WebTestRespons.Cookies collections contain Add method, indexer, but no Remove or equivalent. So you can add cookies to the collection, you can change the properties of a cookie, but you cannot delete a cookie.

I spent hours of searching the net, trying to disassemble the Microsoft.VisualStudio.QualityTools.WebTestFramework using reflector and reading your Guide. No results. And then I accidentally found the solution :)

As I said you cannot delete a cookie from the WetTestRequest.Cookies, but you can modify properties of a cookie. If you set the Expired property of a cookie in WebTestRequest.Cookies collection to true then it will not be sent within the request.

Not the most intuitive way I must say. Although now that I know the solution it makes sense to me :)

So, I thought that this information could be helpful for others and you might want to include it in the next versions of your Guide (although the fact that I did not find anyone asking the same question in the net hints me that this is a very rare scenario).

Cheers,
Levon