Thursday, December 2, 2010

Coded UI tests - IE8 validation URL trick

Any test should include “assert” part. Validation of expected Url is common for any web tests. I use “Coded UI Test Builder” for capturing application objects and for finding out their right properties that are need to be validated. When object is captured it is indicated by the blue outline.

I selected the Address Bar in IE8, but this object did not include any property with url address. I was surprised, because it worked as expected for IE7.



After several efforts, I decided to post the question to the “Visual Studio UI Automation Testing” forum (see more detail here)
Finally, the right object was found: control type – HtmlDocument, property – PageUrl.

Saturday, November 13, 2010

Custom Web Request Test Plugin – Extracted by Regex

Web test requests might include Form Post or QueryString Parameters. For example, if some link of the web site should be clicked, these parameters might include ID of this link. In previous post I showed how to use data source in such case. But data source contains Name of the target link, but not it ID value. Of course, we can add ID value to the data source, but if this ID is unknown for us. For example, in the first request we create application data with corresponding name from the data source and in the second request we click on the newly created item. For such case following custom web request plugin can be created:
[Description("Extract by RegEx \n Sample BeginRegEx + e.WebTest.Context[TextToSearch].ToString() + EndRegEx")]
public class ExtractByRegEx : WebTestRequestPlugin
{
    [Description("Context paramete with UserName")]
    public string ContextParamWithSearchValue
    { set; get; }

    [Description("Context param name to store UserID value")]
    public string ContextParamToStoreValue
    { set; get; }

    [Description("First part of RegEx")]
    public string BeginRegEx
    { set; get; }

    [Description("End part of RegEx")]
    public string EndRegEx
    { set; get; }

    public override void PostRequest(
        object sender, PostRequestEventArgs e)
    {
        if (e.Response == null)
        {
            return;
        }

        var context = e.WebTest.Context;
        var match =
            Regex.Match(
                e.Response.BodyString,
                string.Format("{0}{1}{2}",
                    BeginRegEx,
                    context[ContextParamWithSearchValue],
                    EndRegEx)
            )
            .Groups[1].Value;

        if (context.ContainsKey(ContextParamToStoreValue))
        {
            context[ContextParamToStoreValue] = match;
        }
        else
        {
            context.Add(ContextParamToStoreValue, match);
        }
    }
}
When plugin is created, add it to the request and fill all necessary parameters:
BeginRegEx – this is the first part of the regex expression,
ContestParamToStoreValue – context parameter for extracted value,
ContextParamWithSearchValue – data source value,
EndRegEx – last part of the regular expression.


Context Parameters with extracted value can be used as the data source in further requests.


For create and check regular expression you may use this link.

Sunday, October 31, 2010

PDC10: Test Automation Everywhere

Overview of automation tests in VS 2010 and how they can be integrated with build process - Test Automation Everywhere.

Download Materials - FT53 Test Automation Everywhere.

Friday, October 22, 2010

Web Test & Data Source

One of the benefits of web tests in VS that they can be combined into the scenario. For example, Scenario includes two web tests and each of them uses the same data from data source.  I guess, it will be more elegant to have such data source in Scenario and do not add it to the each of test separately. Magic property of data source “Select all columns” will help us to do this.


After that, all columns will be accessible in the Context. Each column will be automatically binded to the corresponding context parameter with name “DataSourceName.TableName.ColumnName”.

For example, we need to check response and find value from the data source. Custom Validation rule will help.
[Description("Validate text from data source column at the response")]
public class ValidateData : ValidationRule
{
    [Description("Binded to the DataSource Context parameter name = DataSourceName.TableName.ColumnName")]
    public string DataSourceName { set; get; }

    public override void Validate(object sender, ValidationEventArgs e)
    {
        if (DataSourceName == null)
            return;
        if (e.Response.BodyString == null)
            return;

        var searchData = e.WebTest.Context[DataSourceName].ToString();
        e.IsValid = e.Response.BodyString.Contains(searchData);
        e.Message = e.IsValid
            ? string.Format("{0} found", searchData)
            : string.Format("Did not find  {0}", searchData);
    }
}

Validation rule can be added by the right click on the request that should be validated. Fill DataSourceName value and run the test.
Validation result will be at the “Details” tab of the web test result file.

Tuesday, October 19, 2010

Getting Started

It is common case when you come across with new tools and try to find out as much information as possible to understand the main approach and features of this tool. Sometimes it is difficult to extract really useful information from the huge amount that is presented. I decided to share some useful links here:

If you a not common with web, performance testing, I guess this video will be useful

If you just started web testing with Visual Studio, pay your attention to the following resources:

Blogs:
Ed Glas's blog on VS load testing - extremely useful blog, my favorite one.
Sean Lumley's Blog
YuTong's Blog
Bill Barnett's blog

Forum: 
Visual Studio Web Performance and Load Testing Forum

Documentation:
Web testing guidance on MSDN
Visual Studio Performance Testing Quick Reference Guide - provide quick reference points around various aspects of Visual Studio performance testing features that may not be covered in core documentation, or may not be easily understood.

Additional tool:
Fiddler - helps to catch web request that cannot be caught by VS.