Running the Lightweight Test Automation Framework for ASP.NET from a separate application

Published Tuesday, December 02, 2008 1:09 AM

In some instances it might be best if your tests did not run in the same application as the website being tested.  This is where the “IApplicationPathFinder” interface comes into play.  If you implement this interface you will see that it only has one method “GetApplicationpath.”  What this does is allow you to specify a prefix of sorts for the navigate method.  When you call navigate on a HTMLPage it uses a ApplicationPathFinder to get the location it should look for the website at.  For example, the framework will implement this interface and simply return the request path by default.  Creating your own ApplicationPathFinder class allows you to specify where to look for the website, there is nothing stopping you from telling it to look for “http://foo.com.”  The fallowing code shows a simple implementation of the IApplicationPathFinder interface, that points to a second test application. This code is place in the DrivePage that is located in the “Test” folder.

<script runat="server">
    public class TestApplicationPathFinder : Microsoft.Web.Testing.Light.IApplicationPathFinder
    {
        public string GetApplicationPath()
        {
              return "http://localhost/TestApp2";
        }
    }

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        Microsoft.Web.Testing.Light.ServiceLocator.ApplicationPathFinder = 
		new TestApplicationPathFinder();
    }
</script>

Okay, lets take a look at what is really going on here in the code.  First I choose to include the  implementation of the IApplicationPathFinder interface in the DriverPage, however, this could easily be moved to its own file/assembly.  Other than that the code is pretty straight forward, set the ApplicationPathFinder property on the ServiceLocator to an instance of your implementation.

There are numerous reason you might want to run the the test application separately from the site you are testing.  Here is a simple implementation that allows you to store your test application in a central location and pass the location of the site to be test to it.  You could use a URL like “http://localhost/Test?tag=localhost2&filter=true&path=http%3A%2F%2Flocalhost2&run=true” to the navigate and have the test page look for the site at “http://localhost2,” show only the test with the tag name “localhost2,” and run them once navigation is complete.  You could see how you could use this to set up a regression test bed, by storing all your tests in one location and pointing them to the proper servers for the pages.

<script runat="server">
    public class TestApplicationPathFinder : Microsoft.Web.Testing.Light.IApplicationPathFinder
    {
        public string Path { get; set; }

        public TestApplicationPathFinder(string path)
        {
            Path = path;
        }
        
        public string GetApplicationPath()
        {
            return Path;
        }
    }

    protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);
        string path = this.Request.Params["path"];
        if(!string.IsNullOrEmpty(path))
            Microsoft.Web.Testing.Light.ServiceLocator.ApplicationPathFinder = 
		new TestApplicationPathFinder(path);
    }
</script>
Hopefully this gives you some insight into the power that the Lightweight Test Automation Framework for ASP.NET has and how you can leverage that power.  You can download the framework here. Please let me know if you have any questions.

Comments

# Mohan said on Wednesday, August 11, 2010 1:50 PM

Hi,

Is there any way to test pages which are out this application, I mean to say we have some outside pages (http://www.msn.com) we would like to do actionson this page. Can you please point me how to do this thing.

Kindly let me know if you need any info.

# Federico Silva said on Saturday, August 14, 2010 6:02 PM

LTAF does not have this capability out of the box, however, you can look at this blog post for a way to enable this scenario.

forums.asp.net/.../1385709.aspx

If you have questions regarding LTAF you can use the forum above, which I monitor constantly.

Thanks,

Federico

# weblogs.asp.net said on Friday, April 01, 2011 2:41 AM

Running the lightweight test automation framework for asp net from a separate application.. I like it :)

# sdfsdgfd said on Thursday, April 14, 2011 9:05 PM

Very informative post. Thanks for taking the time to share your view with us.

# weblogs.asp.net said on Thursday, April 28, 2011 1:42 AM

Running the lightweight test automation framework for asp net from a separate application.. Not so bad :)

# weblogs.asp.net said on Saturday, June 11, 2011 1:39 AM

Running the lightweight test automation framework for asp net from a separate application.. Awful :)

# Cheap oem software said on Friday, October 28, 2011 2:43 AM

PONEUg Yet, much is unclear. Could you describe in more details!...

# cheap oem software said on Tuesday, February 07, 2012 2:40 PM

hfu7En I would add something else, of course, but in fact almost everything is mentioned!....

Leave a Comment

(required) 
(required) 
(optional)
(required)