In Web Tests, How to Validate the values on a grid ?

I want to validate the values that are shown on a grid , based on the values that are selected on a Combo.(Herein internally, the grid gets filled, when the combo box value is changed.) I would also like to know the selected row from the grid, so as to try it... or else Manual testing has always been there at our help ?Idea

[388 byte] By [WilsonThampiJohn] at [2007-12-20]
# 1
You can do this with a validation rule. If the value in the combo is displayed on the same page as the grid, then you could do it with one valistion rule. If the value of the combo is on the previous page, then you would need to use an extraction rule to pull out the value of the combo, store this value in the web test context, and then have a validation rule on the page with the grid which pulls the value out of the context and validates the data in the grid. You can create a rule by doing the following:

1) Create a test project
2) Add a class library project to the solution with the test project.
3) In the class library project add a reference to the Microsoft.VisualStudio.QualityTools.WebTestFramework.dll. This can be found on the .NET tab of the Add Reference Dialog.
4) In the class in the Class Library project add a using statement for Microsoft.VisualStudio.QualityTools.WebTestFramework
5) Have the class extend the ValidationRule class.
6) Right Click on ValidationRule and choose, Implement Abstract Class. This will create the method that you need to implement which is the Validate method.
7) One of the properties of the ValidationEventArgs class which is passed into the validate method is the Response. This object gives you access to the HTML Response. You can get the response as a string and then parse it to find the values you are looking for or you can access the tags collection and pull out the html tags you are interested in.
8) In the Validate method, set the IsValid property to indication success or failure for the rule.
9) Then add the class library project as a reference to the Test Project.
10) Find the request in your web test which you want to validate data for and right click on the request and choose add validation rule.
11) Select your rule and choose OK.
12) Play back the test to verify the rule did what you expected.
13) As you are developing the rule, it is useful to run the web test under the debugger. You can add break points in your rule and then run the web test under the debugger from the test view window. Open this window by Clicking the top level Test menu -> Windows - > Test View. Your test should appear in this window. Select your test and then right click on it and choose Debug Selection.

If you need to extract a value from one reqeust and access it in another request, following similar steps, except implement the extraction rule class. In the extraction rule, add the value you want to access to to the context. The context is available off of the WebTest property of the event args class. Anything you add to the context is available to future requests.

slumley at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Visual Studio Team System - Web and Load Testing...
# 2

Hi,

Can someone point me to a code example? I'm really new to this stuff and need some help. :)

Thank you.

Yulia at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Visual Studio Team System - Web and Load Testing...
# 3
Here is a code example for a custom validation rule: http://blogs.msdn.com/joshch/archive/2005/11/02/488398.aspx
slumleyMSFT at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Visual Studio Team System - Web and Load Testing...
# 4

Hi, Slumley.

I can create a custom validation rule. I was hoping someone will have an example of a custom validation rule, validating a value in a grid control or any other type of control, so I can see how it's done. Can you point me to such example?

Thank you.

Yulia at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Visual Studio Team System - Web and Load Testing...
# 5

Hi, all.

Can someone point me to a code sample where a control value is being validated?

Any help will be really appreciated.

Thank you.

Yulia at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Visual Studio Team System - Web and Load Testing...
# 6

All,

I tried the following steps, but still i am not able to find an extra validation rule getting added.

The code which i have added is

===================================

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Text;

using Microsoft.VisualStudio.TestTools.WebTesting;

using Microsoft.VisualStudio.QualityTools.WebTestFramework;

namespace OcracokeSamples

{

public class ValidateResponseUrl : ValidationRule

{

private string _urlStringToFind = String.Empty;

private bool _failIfFound = true;

[Description("If true, validation fails if the specified string is found in the response URL. If false, validation fails if the specified string is not found in the response URL.")]

public bool FailIfFound

{

get { return _failIfFound; }

set { _failIfFound = value; }

}

[Description("The string to search for in the response URL. For example, enter 'Error.aspx' if you want to make sure the server does not redirect to that error page.")]

public string UrlStringToFind

{

get { return _urlStringToFind; }

set { _urlStringToFind = value; }

}

public override string RuleName

{

get { return "Validate Response URL"; }

}

public override string RuleDescription

{

get { return "Verifies the response URL. This rule can be used to make sure a redirect to an error page does not occur, for example."; }

}

public override void Validate(object sender, ValidationEventArgs e)

{

//make sure the string to find has a value

if (String.IsNullOrEmpty(_urlStringToFind))

{

throw new ArgumentException("The UrlStringToFind property cannot be null or empty string.");

}

bool found = e.Response.ResponseUri.OriginalString.IndexOf(_urlStringToFind, StringComparison.OrdinalIgnoreCase) != -1;

string foundMessage = found ? "was" : "was not";

//set the result message that will appear in the web test viewer details tab and the load test error table

e.Message = String.Format("The string '{0}' {1} found in the response URL.", _urlStringToFind, foundMessage);

//set whether the validation passed or failed

e.IsValid = found != _failIfFound;

}

}

}

======================================

When i build the solution the message what i got is below

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Vbc.exe /noconfig /imports:Microsoft.VisualBasic,System /rootnamespace:TestProject10 /doc:obj\Debug\TestProject10.xml /define:"CONFIG=\"Debug\",DEBUG=-1,TRACE=-1,PLATFORM=\"AnyCPU\"" /reference:..\..\..\..\..\..\..\WINDOWS\assembly\GAC_MSIL\Microsoft.VisualStudio.QualityTools.UnitTestFramework\8.0.0.0__b03f5f7f11d50a3a\Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll,"d:\Program Files\Microsoft Visual Studio 8\Common7\IDE\PublicAssemblies\Microsoft.VisualStudio.QualityTools.WebTestFramework.dll",C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\System.dll,..\..\TestProject11\TestProject11\bin\TestProject11.dll,..\..\TestProject8\TestProject8\bin\TestProject8.dll /debug+ /debug:full /out:obj\Debug\TestProject10.dll /target:library "My Project\AssemblyInfo.vb" UnitTest1.vb WebTest1Coded.vb WebTest2Coded.vb

TestProject10 -> C:\Documents and Settings\jrajeev\My Documents\Visual Studio 2005\Projects\TestProject10\TestProject10\bin\TestProject10.dll

========== Rebuild All: 1 succeeded, 0 failed, 0 skipped ==========

Please let me know what am i missing here, or in case you need some more details

withRajeev at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Visual Studio Team System - Web and Load Testing...
# 7

For a custom validation or extraction rule to show up in the rules dialog, there must be reference in the project containing the web test to the assembly containing the rule. Also, the rule must be declared as a public class (which is the case in the code you posted).

You rule you posted is C# and the Web tests are VB. So, you'll need a reference in the VB project to the assembly containing the rule.

Thanks,
Rick

RickPotts-MSFT at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Visual Studio Team System - Web and Load Testing...
# 8

Thanks Rick,

I have added the code in C# and also the web test in C#.

Even then i was not able to find the extra validation rule.

I believe when we add reference to the C# code from the webtest it should create a reference to the web test and the C# code, let me know if my understanding is correct.

If not then i like to get how to do the following :

"For a custom validation or extraction rule to show up in the rules dialog, there must be reference in the project containing the web test to the assembly containing the rule."

Thanks for your support

withRajeev at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Visual Studio Team System - Web and Load Testing...
# 9

Here's one example...

A solution contains two projects, one project is a class library project which contains a class implementing a custom validation rule (RuleProject). The custom validation rule class must be declared as public and extend ValidationRule. The other project is a test project containing a web test (WebTestProject).

To add the validation rule from RuleProject to the web test in WebTestProject, you would need to add a project refernce for RuleProject to WebTestProject (right click on the references node and choose add reference; then choose Projects tab and select RuleProject). You should now see the custom validation rule listed in the dialog when you attempt to add a validation rule to a web test request.

Note, if the custom validation rule resides in the same project as the web test, there should be no need for the project reference. The rule should appear in the dialog as long as it is declared as public.

Does this help?
Thanks,
Rick

RickPotts-MSFT at 2007-9-9 > top of Msdn Tech,Visual Studio Team System,Visual Studio Team System - Web and Load Testing...

Visual Studio Team System

Site Classified