One of the features I really enjoy in WebAii v2.0 is the RecycleBrowser option. It changes the behavior of your tests, i.e. they keep running in the same browser instance (when set to ‘true’) instead of opening a new browser for each test. The default value is ‘false’ for consistency with the previous framework versions behavior. You can programmatically update that setting via the Settings class or using the Application’s config file.
However, there are some details you should have in mind when using that option.
We do use the RecycleBrowser option in the WebAii Testing Framework Sample Tests projects (AJAX and Silverlight) from the very beginning. Those projects are based on the WebAii VSTS support.
If you install the framework and load any of those projects in VS 2008, you will notice the settings initialization in our base test class. The important initialization method looks like this (note our base test class extends the ArtOfTest.WebAii.TestTemplates.BaseTest template):
public class RadControlsBaseTest : BaseTest
// Use TestInitialize to run code before running each test
public void MyTestInitialize()
#region WebAii Initialization
// Initialize(this.TestContext.TestLogsDir, new TestContextWriteLine(this.TestContext.WriteLine));
Settings settings = GetSettings();
settings.DefaultBrowser = BrowserType.InternetExplorer;
settings.RecycleBrowser = true;
settings.BaseUrl = "http://demos.telerik.com/aspnet-ajax";
settings.ClientReadyTimeout = 60000;
settings.ExecuteCommandTimeout = 60000;
settings.AnnotateExecution = true;
settings.AnnotationMode = AnnotationMode.All;
// Now call Initialize again with your updated settings object
Initialize(settings, new TestContextWriteLine(this.TestContext.WriteLine));
// Set the current test method. This is needed for WebAii to discover // its custom TestAttributes set on methods and classes. // This method should always exist in [TestInitialize()] method.
#endregion // // Place any additional initialization here //
And if you end up with this code only, you will notice the browser launches only once (as expected) even though you call
in each of your tests. Since the browser does not get closed at the end of the test though, it is kept open at the end of the entire group of tests’ execution. You can use the BaseTest.ShutDown()to close the browser. The method needs to be called in routine marked with the ClassCleanup attribute for each of the test classes* that inherit from our base test. This way you end up with closed browser no matter which tests you select to execute.
Sample code follows:
public class GridPagingTests : RadControlsBaseTest
//Use ClassCleanup to run code after all tests in a class have run.
public static void GridPagingClassCleanup()
public void PagingAjaxTest()
GridPager pager = Find.ById<RadGrid>("RadGrid1").Pager;
Wait.For<GridPager>(myPager => myPager.CurrentPageIndex == 1, pager, 5000);
I hope this explanation helps!
In the next posts I will try to cover some more features of the new WebUI Test Studio v2.0 and the testing framework.
* Unfortunately due to an issue in VSTS Test (an old one I originally found mentioned here) concerning inherited tests you cannot implement the ClassCleanup method in the base class only – it doesn’t get called if it’s not a part of the inheriting classes.