TestDriven.Me

I hope to spend some time discussing testing with VB.NET. I don't think of myself as an expert, but I have had some experience and certainly some opinions. I will try to share some of those opinions along with some information and hopefully generate some discussion so that we all can improve our skills a bit.
WatiN API - ClearCookies

I could not get this method to work as expected for me.

 

It is designed to clear cookies for either a specific web site or all cookies depending on whether you pass a web site URL as its parameter.  When I tried it in the below test, it failed because of no security access to clear the cookie data in IE7.  Since I did not want to modify system access because that did not seem proper for testing, I just decided that clearing cookies would probably not be that important.

 

Example of Usage

 

    ''' <summary>
    ''' Ensure that browser cookies do not affect
    ''' the results of clicking the OK Button.
    ''' </summary>
    ''' <remarks>
    ''' currentURL is a Private Const =
    ''' "http://localhost:3587/Default.aspx"
    ''' OKButton is a Private Const = "OKButton"
    ''' MessageTextBox is a Private Const = "MessageTextBox"
    ''' </remarks>
    <Test()> _
        Public Sub TestClearCookies()
        Dim StringValue As String = ""
 
        Using ie As IE = New IE(currentURL)
 
 
            'Method ONE - Fully specify find criteria
            ie.Button(Find.ById(New Regex(OKButton))).Click()
            Assert.IsTrue(ie.TextField(Find.ById(New Regex(MessageTextBox))).Text.Contains("OK"), "TestButtons did not find OK in the textbox after OK button clicked.")
            ie.CaptureWebPageToFile("c:\temp\step1.jpg")
 
            ie.SetCookie("http://google.com", "test=Cookie Test")
            ie.TextField(Find.ById(New Regex(MessageTextBox))).Value = "Test"
            ie.CaptureWebPageToFile("c:\temp\step2.jpg")
            Assert.IsTrue(ie.TextField(Find.ById(New Regex(MessageTextBox))).Text.Equals("Test"), "Textfield did not reset.")
 
            StringValue = ie.GetCookie("http://google.com", "test")
            ie.TextField(Find.ById(New Regex(MessageTextBox))).Value = StringValue
            ie.CaptureWebPageToFile("c:\temp\step3.jpg")
 
            ie.TextField(Find.ById(New Regex(MessageTextBox))).Value = "Test"
            ie.CaptureWebPageToFile("c:\temp\step4.jpg")
            ie.ClearCookies("http://google.com")
            ie.SetCookie("http://google.com", "test=")
 
            StringValue = ie.GetCookie("http://google.com", "test")
            ie.TextField(Find.ById(New Regex(MessageTextBox))).Value = StringValue
            ie.CaptureWebPageToFile("c:\temp\step5.jpg")
 
 
            Assert.IsTrue(ie.TextField(Find.ById(New Regex(MessageTextBox))).Text.Equals("test"), "Cookie data remained when should have been cleared.")
 
        End Using
 
    End Sub

 


 

This test will fail on the line with ClearCookies, because WatiN does not have access to delete cookies.  If you comment out the ClearCookies command, you can change the data manually by setting the cookie to an empty string and the test will pass.

 

Contents: Table of Contents Previous Page: WatiN API Reference - ClearCache Next Page: WatiN API Reference - Close

 

Published Thursday, July 03, 2008 9:53 AM by ddodgen

Comments

No Comments