In one of the last posts we looked at testing MOSS2007 using Visual Studio 2008. In that post we looked at uploading of documents.
http://www.helloitsliam.com/archive/2008/03/10/moss2007-testing-using-visual-studio-team-system-2008.aspx
In this post we will look creating sites using the following:
- Visual Studio 2008 Web Test
- Data Source (XML)
- Web Test Plug-in
So let's begin, firstly we need to launch Visual Studio 2008 and create a new project based on the Web Test template. Once we have this we will then select to add a new a new test.
Select the web test template.
Once we have our web test created, this will then launch Internet Explorer in recording mode.
As we access various options the recorder pane will populate with the URL links that we visited. Our first task is to select the "Create Site" menu item as shown below:
We then need to complete the form as normal, mine is as follows:
Once it is completed the recorder panel should now look similar to this. Notice the list is not that long but one of the items can be expanded.
When this is expanded you should see all the posted form items that are needed for creating a site.
The most important items from the form post are shown below. We will modify these later.
We can now press the stop button and this will take us back to Visual Studio. Once there we need to remove the following two items as these are not needed. The first link appears when we access the site; the second appears when you select the "Site Actions" menu.

For our project we only want to run the necessary items and nothing else. If we leave these extra pages in, it will mess our test results up. Now we have our project working, we want to make it as generic as possible, so firstly we need to replace the first part of the URL with variable that can be populated.
To do this we will need to add a data source and then read this value in at runtime. So to complete this we need to add a new item to our project.
We need to select an XML file as the item type.
No we have our XML file we simply need to add the following:
Once you have saved the file we need to add a data source to the project. To do this right click on the project and select "Add Data Source".
Follow the wizard and complete as follows:
Now we have this it should be listed as shown below:
Now we have the data source connected we can now change the URL properties. To do this select the URL in the test pane and edit the properties that appear on the right.
If you select the dropdown list arrow that appears on the property you can select the data source values as shown below.
For our test we will simply overtype the values as shown below:
Now we are using a dynamic XML file for the URL we now need to create a method of naming the team sites we create with unique names. For this we will add a new project to our solution.
You will need to select the class library template.
I have removed the initial class file that gets created and added a new one with the following name:
Once we have our class library project we need to add the following reference:
Make sure you check that the following reference is added:
Now we have our references we need to add the following code block:
Notice within the code that we have based our code on the Web Test Plug-in class and added the following methods:
- PostWebTest
- PreWebTest
These two methods will get called either before or after the plug-in is called. We will use the "PreWebTest" and simply check for the existence of a variable and if it exists populate it with a new GUID, this will then be used as the site name. We simply need to build the project now.
Once it is built we need to go back to our original testing project and add a web test plug-in. We will then choose the newly compiled DLL we created.
When the window loads select the following reference.
It should then show up in the testing pane as shown below:
No we have our new DLL connected we can then make changes to the relevant locations. The variable we need to use is the one that we are testing for in the "PreWebTest" code.
The following line needs changing as shown below:
There are a few form post parameters that also need changing, such as the name and URL of the newly created site. They need to be changed as below:
One issue we get when running this test is the response URL that is expected is not the same as the recorded value. To resolve this we can simply delete the "Response URL" line within the test.
The full test should look as shown below:
Now we have our completed project we simply need to run this test.
The test will run and return the results as shown below, notice the newly created site is shown below with the new GUID, which is generated from our code as the name, description and URL of the new site.
As you can see with a little coding and extra functionality you can add into custom DLL's and using external data sources you can create very flexible test plans for MOSS2007. In the next part will look at creating a test pan for searching using SharePoint and then put all the previous tests together to create the following bulk test:
- Access Homepage
- Search for a term in SharePoint and return results
- Create new Team Site
- Create new document library within the newly created site
- Delete created site
Hope this is helpful.