Saturday, July 19, 2008

WebTesting - Fiddler, Visual Studio 2008, MOSS

Goal

  • To enable a team of mixed skills to record webtests.
  • These users must not be restricted to having an installation of Visual Studio 2008.
  • It must be quick and easy to record a test.
  • The tests need to be ported into Visual Studio 2008 for web testing.

Resolution

  • Users create tests with Fiddler2
  • Tests are saved as Archive Zip Files (.saz)
  • The Archive Zip are emailed or stored in a central repository
  • Developers (someone with Visual Studio 2008 with web testing tools installed on it, this is not a default install) open the Archive Zip files and re-save them as webtest files (.webtest).
  • The webtest files are loaded into Visual Studio 2008 and are now available for web testing.
  • If testing that requires scripting is required the webtest can be converted to a code (in Visual Studio 2008)

Steps:

1) Get Fiddler

Install Fiddler2 on all the user's machines. It takes a few minutes to download and get up and running. This blog is written using Fiddler Version (V2.1.6.2).

image

2) Record a web session (Staff Member)
  • Open Fiddler2
  • Open IE (fiddler only runs on I.E. but the idea is just to record the actual testing can be done on different platforms)
  • Record your session.
    In the pic below I have IE & Fiddler2 open.
    I recorded a session by opening up IE and going to google and doing a search for Fiddler2. You will see the captured requests being caught in Fiddler as you browse in IE. image
  • When you are done highlight all the lines in the "Web Sessions" pane image
  • Click "File > Save > Session(s) > in Archive Zip..."
  • Save the .saz file to your disk.image
  • At this point the user recording the test's job is done. The rest of the work is for the developers to get it into Visual Studio 2008.
3) Get the Test Into Visual Studio (Developer)
  • Assuming this is the first time you have loaded up fiddler2 and are using Visual Studio 2008 with web testing tools installed. Testing tools is not a default install of Visual Studio 2008. I have the following installed in VS and think it's this:
    "Microsoft Visual Studio Team System 2008 Test Edition"
  • You have a "Archive Zip File" (.saz) that someone has recorded.
  • Open the .saz file up in Fiddler2
    "File > Load Archive..."
  • Now save the file as a Visual Studio Web Test. First highlight all the lines in the Web Sessions pane of fiddler then click:
    "File > Save > Session(s) > as Visual Studio Web Test"
  • I have called the sample file "BlogTest.webtest"
  • If you get the following error:
    "One or more plugins returned an error, but the remaining plugins executed and the Web Test was written.

    Could not load file or assembly 'Microsoft.VisualStudio.QualityTools.WebTestFramework, Version=8.0.0.0,... "image

  • It is because the Fidder2 plugins are expecting Visual Studio 2005. To get around this:
    • goto the Fiddler2 install folder
    • open "fiddler.exe.config"
    • paste the following code over the existing xml that's in the config file:
      <configuration>
        <runtime>
            <legacyUnhandledExceptionPolicy enabled="1" />
            <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
                <dependentAssembly>
                    <assemblyIdentity name="Microsoft.VisualStudio.QualityTools.WebTestFramework"
                    publicKeyToken="b03f5f7f11d50a3a"
                    culture="Neutral" />
                    <bindingRedirect oldVersion="8.0.0.0"
                    newVersion="9.0.0.0"/>
                    <codeBase version="" href="C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.WebTestFramework.dll"/>
                </dependentAssembly>
            </assemblyBinding>
        </runtime>
      </configuration>
  • Open Visual Studio 2008
  • Create a new Test Projectimage 
  • Add the BlogTest.webtest to your projectimage
  • The test will now be available to run from within the Visual Studio 2008 Web Testing Tools.

    As can be seen below I am running this from within a Virtual Machine that has decided (as per one of it's moods) to have a no talkies to the internet so the test fails.image
  • Done. 
    You now have a webtest in visual studio.  This can be automated to run at regular intervals or can be run after a new piece of functionality has been deployed.
4) Scripting against an existing webtest within Visual Studio

Let us assume one has followed the steps above and we now have a webtest sitting in Visual Studio 2008. What if we now want to do some more in depth testing. For example I have a SharePoint 2007 list that I'd like to try hit all the items in the list. To do so I would get a list of all the items programmatically and then try hit each of these. This will be the topic of another post when I get around to it.

For now here are the steps to convert a webtest into a scripted test.

  • Double click the webtest in Visual Studio to open the testimage
  • In the main pane right click on the Root of the test. In my example it's "BlogTest"image 
  • Click"Generate Code..."
    Visual Studio will now create a class in your solution.image 
  • To test this code:
    • Set a break point in the codeimage
    • open the "Test View Pane" and click:
      "Debug Selection"image 
    • Your break point will now be hitimage
    • Happy Testing!

Conclusion

Using the steps above a team can now build up a library of test Archive Files (.saz) files. This archive can be generated by team members who do not need Visual Studio on their machines. If there are errors with a site then I would suggest

  • whoever finds the error records it
  • saves it in a central repository
  • a developer then brings it into Visual Studio
  • the test then becomes part of an ever growing Test Library.

2 comments:

Ray said...

This is a good post because I am learning fiddler now. :)

But when I use fiddler to record the website , save it as visual studio web test (test.webtest), open VS 2008 test project , and add an existing item (test.webtest), I find test.webtest doesn't have any requests, do I miss something here?

Thank you,

Ray

Ahmet said...

Just in case someone else wondering why there is no talkie with internet:
It is because you did not set a valid proxy.
You can do it by going to your test root node and right click to properties. Edit the proxy value to "default" or any valid proxy you have.