Inside VSTS

VSTS 2008 Web Testing Part 3: Validation Rules

Visual Studio Team System 2008 (both the Testing edition and the Team Suite edition) have a type of test referred to as a Web test. These Web tests are used to test the functionality of Web applications, and are also designed to be used to load test Web applications. In Part 3 of this series on Web tests, we are going to look at how to add validation rules to a Web test. To catch up on current events, check out Part 1 VSTS08 Web Testing and Part 2 Running a Web Test.

What are Validation rules
In a Visual Studio Team System 2008 Web test, a validation rule is used to help verify that a Web application is performing correctly. It does this by checking for the existence of text, tags, or attributes on the page returned by the Web request. Validation rules are also used to verify the amount of time it takes a request to finish. Finally, validation rules can be used to verify the existence of form fields and their associated values.

Adding a validation rule to a Web test
Validation rules are added to a Web test using the Web Test Editor in Visual Studio 2008. Figure 1 displays the Web test we have been working with in Part 1 and Part 2 of this series.


[Click on image for larger view.]
Figure 1.

For the Web site we are testing, we want to make sure that once you log into the site, that it displays the message "Welcome <username>", where <username> is the user name used to log into the site. To do this, we are going to add a validation rule to the Web request indicated by the red arrow in Figure 1.

Right-click on the Web request in the Web Test Editor, and from the context menu select "Add Validation Rule". This will open the Add Validation Rule window, as shown in Figure 2.


[Click on image for larger view.]
Figure 2.

You have several validation rule options out of the box:

  • Form Field - Verifies the existence of a form field with the specified name and value.
  • Find Text - Verifies the existence of the specified text in the response.
  • Maximum Request Time - Verifies that the request finishes within a specified amount of time.
  • Required Attribute Value - Verifies the existence of a specified HTML tag that contains an attribute with a specified value.
  • Required Tag - Verifies the existence of specified HTML tag in the response.
  • Response URL - Validates that the response URL after redirects are followed is the same as the recorded response URL. QueryString parameters are ignored.

For this scenario, we want to make sure the required phrase is in the response from the Web server, so we have selected the Find Text validation rule. The right side of Figure 2 shows the properties for the Find Text validation rule:

  • Level - This property is important when used in conjunction with load testing. The possible values are Low, Medium and High.
  • Find Text - This is the text we are looking for in the response.
  • Ignore Case - Determines whether case matters or not.
  • Use Regular Expression - Allows you to use a regular expression in the Find Text field.
  • Pass If Text Found - Determines whether the test passes or fails based on whether the text is found or not found.

For this scenario, we are looking for the words "Welcome Alok". We are not using a regular expression, and case does not matter. The test will pass if the words are found. Click the OK button to close the Add Validation Rule window. Figure 3 shows the Web test in the Web Test Editor, with the addition of the validation rule.


[Click on image for larger view.]
Figure 3.

Running The Web Test
Now that we have added a validation rule to our Web test, it is time to run the Web test and view the results. In the Web Test Editor, click the Run Test button to run the Web test. Figure 4 shows the results of running the Web test.


[Click on image for larger view.]
Figure 4.

By selecting the request to which we added the validation rule and then selecting the Details tab, we can see the results from the validation rule. For this test, our validation rule passed, indicating that it found the "Welcome Alok" phrase in the response object.

Making the Validation Rule Fail
Now let's intentionally make the validation rule fail, to show what happens when a Web test fails. Return to the Web test in the Web Test Editor and select the validation rule we created earlier. In the Properties window for the validation rule, change the Find Text field to be "Welcome Fred". Save the Web test and then run it again. This time, the test will fail, as shown in Figure 5.


[Click on image for larger view.]
Figure 5.

Notice at the top of the test is a red X, indicating the test has failed. A red X also indicates which Web request failed. If we select the Web request and click the Details tab, we can see that the validation rule failed, because the text "Welcome Fred" did not appear in the HTML response object.

Conclusion
In this series of columns on Web testing, we have touched the surface on what you can do with a Web test. We have shown you how to create and run a Web test, as well as how to add validation rules to a test. For basic testing, this will get you started. Once you start delving into Web testing more, you will want to look at how to utilize extraction rules, and even how to create your own custom validation and extraction rules.

About the Author

Mickey Gousset spends his days as a principal consultant for Infront Consulting Group. Gousset is lead author of "Professional Application Lifecycle Management with Visual Studio 2012" (Wrox, 2012) and frequents the speaker circuit singing the praises of ALM and DevOps. He also blogs at ALM Rocks!. Gousset is one of the original Team System/ALM MVPs and has held the award since 2005.

comments powered by Disqus

Featured

  • Build Your First AI Applications with Local AI

    "AI right now feels like a vast space which can be hard to jump into," says Craig Loewen, a senior product manager at Microsoft who is helping devs unsure about making that first daunting leap.

  • On Blazor Component Reusability - From Day 0

    "We want to try to design from Day One, even Day Zero, with reusability in mind," says Blazor expert Allen Conway in imparting his expertise to an audience of hundreds in an online tech event on Tuesday.

  • Decision Tree Regression from Scratch Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of decision tree regression using the C# language. Unlike most implementations, this one does not use recursion or pointers, which makes the code easy to understand and modify.

  • Visual Studio's AI Future: Copilot .NET Upgrades and More

    At this week's Microsoft Ignite conference, the Visual Studio team showed off a future AI-powered IDE that will leverage GitHub Copilot for legacy app .NET upgrades, along with several more cutting-edge features.

  • PowerShell Gets AI-ified in 'AI Shell' Preview

    Eschewing the term "Copilot," Microsoft introduced a new AI-powered tool for PowerShell called "AI Shell," available in preview.

Subscribe on YouTube