WebAii Test Settings and Configuration

As is common with .NET components WebAii can be configured through .config files and even better it uses standard .NET features for configuration.  In this article I will show you have to prepare a configuration file and list all of the possible settings that control WebAii tests.

Setting up a configuration file

Although we create our tests in a Class Library project we can still use the standard App.config file and let VS compile and deploy it to the bin folder as we would do with a full blown application.  If you are deploying tests to a build server you will need to include the generated file, and if you are using the NUnit GUI to run tests you may need to create an NUnit project and reference the file.  I’ll show you have to do the latter at the end of this post.
To get started add a new Application Configuration File item to your project, no need to change the name, you should end up with an empty configuration file like this:
   1: <?xml version="1.0" encoding="utf-8" ?>
   2: <configuration>
   3: </configuration>
.NET supports custom Configuration Sections and WebAii includes a handler for it’s own settings and the first step of preparing the configuration file is to add a reference to this handler.  The handler is referenced via a section element within the configSections element which is a top level element.  Edit App.config to add the handler like this:
   1: <?xml version="1.0" encoding="utf-8" ?>
   2: <configuration>
   3:     <configSections>
   4:         <section name="WebAii.Settings"
   5:                          type="ArtOfTest.WebAii.Core.SettingsConfigSectionHandler, />
   6:                             ArtOfTest.WebAii"
   7:     </configSections>
   8: </configuration>
What this does is tell the .NET configuration framework to load the handler referenced and use it to parse and process an element named WebAii.Settings when it is encountered.  Not I have left the versioning out of the assembly reference so that it works with any version referenced.  So we can now add such an element to finish preparing our configuration file like this:
   1: <?xml version="1.0" encoding="utf-8" ?>
   2: <configuration>
   3:     <configSections>
   4:         <section name="WebAii.Settings"
   5:                          type="ArtOfTest.WebAii.Core.SettingsConfigSectionHandler, />
   6:                             ArtOfTest.WebAii"
   7:     </configSections>
   8:  
   9:     <WebAii.Settings />
  10:  
  11: </configuration>
With this in place we now have two choices for controlling WebAii tests through App.config or in code as demonstrated in the article Setting Up a WebAii Test Project with NUnit.  Typically you will set defaults in App.config and then only use code to override them when necessary.
One important thing you need to remember is that in App.config settings are defined as Camel cased attributes of the WebAii.Settings element whereas in code the properties of the Settings class are Pascal cased.  In the table that follows I will include both and in the sample code accompanying this article I have included all possible settings in App.config with their default values.

Table of settings

The following table show all possible settings with, their default values and a description with comments based on my exprience to date.
 
Config Code Default Value Description
annotateExecution AnnotateExecution false Controls whether simulated user interactions are “annotated” as they happen.  For example if the test simulates a click on a button a bright yellow popup will flash at the point where the click occurs.  This is useful where the tests are designed for manual execution as they help a watching user follow the test more easily.  One thing to not here is that with this set to false you cannot use custom annotations, which I find very useful.
annotationMode AnnotationMode All Controls the type of annotations that are displayed.  Possible values are All, CustomOnly or NativeOnly.  I tried to use this to display only the annotations that I added in my test code using the ActiveBrowser.Annotator.Annotate method but this does not appear to be what is meant be a Custom annotation since all annotations were hidden when I set this option to CustomOnly.  It seems custom annotations are only supported through design canvas tools.
  AspNetDevServerPhysicalPath   Read only and set by the framework to the path of WebDev.WebServer.exe when LocalWebServer is true
aspNetDeverServerPort AspNetDevServerPort -1 Controls the port for running the ASP.NET web server under if this option is enabled for running tests.  Only applicable it LocalWebServer is true
baseUrl BaseUrl String.Empty Base Url for NavigateTo operations.  If you set this you must pass relative Urls to any NavigateTo calls.
clientReadyTimeout ClientReadyTimeout 30000 Time to wait (in milliseconds) for the browser to complete loading after it is launched.  A TimeoutException is thrown if the browser is not ready within the time set.
createLogFile CreateLogFile true Controls whether a log file is created on disk when tests are executed.
defaultBrowser DefaultBrowser InternetExplorer Controls the browser launched by default when tests are executed.  I found this useful for switching the whole test suite from one browser to another and using templated values we were able to get our build server to compile tests for each browser from a single code base.
enableScriptLogging EnableScriptLogging false Controls whether execution of JavaScript is logged.
enableSilverlight EnableSilverlight false Controls whether automation of Silverlight applications is enabled.  Obviously this will always need to be true when testing Silverlight and I always set it in code to ensure that it cannot be disabled via configuration
enableUILessRequestViewing EnableUILessRequestViewing false Controls whether UI browsers like IE can be used to debug tests running against a page without a UI.  For example you might be testing an .aspx page that does not have a UI but are testing via WebAii.
executeCommandTimeout ExecuteCommandTimeout 20000 Time to wait (in milliseconds) after a command is sent to the browser.  For example a call to User.Click will send a request to the browser to click on an element, if the browser does not complete the operation and return a response within the specified period a TimeoutException is thrown
executionDelay ExecutionDelay 0 Time to wait (in milliseconds) between each command sent to the browser.  Increasing this value allows a watching user to keep up with the test.  I found 200 milliseconds to be a good compromise slowing the test down enough to allow it to be watched but not so much as to make the test run slow during Continuous Integration builds.
  Is64BitOs   Read only indicating whether the operating system where the test is running is 64 bit.  This might be useful where tests need to behave differently in 32 and 64 bit implementations.
  IsStressRecordingMode   Read only and used only internally by tools
  IUserInteractiveMode   Read only indicating whether the user running the tests is an interactive user.  Unless you are running tests via an automated build utility like CruiseControl or TeamCity this will always be true.   You can check the value of this property in test code to make sure you do not perform any user interactions that will result in an error because the mouse and keyboard are not available.
killBrowserProcessOnClose KillBrowserProcessOnClose false Controls whether the browser process will be killed when the browser window used for a test is closed.  Generally you want to leave this set at false unless you are certain the test will always fire up a new process for the test.  Some browsers like FireFox run all windows in a single process so if this is set to true when using such a browser the whole process will be killed and all windows that were open will be closed too.
localWebServer LocalWebServer none Controls whether to use the local ASP.NET development server.  Not really applicable for Silverlight testing.  The only other value supported other than the default is AspNetDevelopmentServer.  If you enable this you must also set the WebAppPhysicalPath
logAnnotations LogAnnotations false Controls whether annotations are written out to the WebAii log files
logLocation LogLocation C:\WebAiiLog Physical location where log files will be created.  This location will be used for captured bitmaps as well as logs
queryEventLogErrorsOnExit QueryEventLogErrorsOnExit false Controls whether the Windows Event Application Event Log will be checked for errors logged by the application being automated when the Manager object shuts down.  This is useful to consolidate all errors into a single location as any errors found will written to the WebAii log
recycleBrowser RecycleBrowser false Controls whether a single browser is used for all tests during a session.  With the default each test method will fire up a new browser.  Whilst this is useful for debugging and testing tests for any actual test session you will want this set to true to use a single browser for the entire session.  When you set this to true ensure you call Shutdown from a TestFixtureTearDown method or similar otherwise the browser will not close at the end of the session.
silverlightApplicationPath SilverlightApplicationPath String.Empty Physical path from which to load a Silverlight application.  Supports loading a Silverlight application directly from a .xap file.  I haven’t tried this out yet since everything I have needed to test so far needs an HTTP context to access services.
silverlightConnectTimeout SilverlightConnectTimeout 30000 Time to wait (in milliseconds) for a Silverlight application to load and for WebAii to connect.  Throws a TimeoutException if the specified period is exceeded
simulatedMouseMoveSpeed SimulatedMouseMoveSpeed 0.3 Controls the speed (in pixels per millisecond) of the mouse during Move or Drag/Drop operations.  I found the default to be adequate but not sure it is realistic so you may want to experiment if you want your tests to realistically simulate user interaction.
unexpectedDialogAction UnexpectedDialogAction HandleAndFailTest Controls how WebAii will handle an unexpected dialog being displayed during a test.  Valid values are DoNotHandle, HandleAndContinue or HandleAndFailTest
useHttpProxy UseHttpProxy false Controls whether to use the HTTP Proxy built into the WebAii framework.  This setting has not effect when EnableSilverlight is set to true as the proxy is required for automating Silverlight applications.
verboseHttpProxy VerboseHttpProxy false Controls whether the built in HTTP Proxy produces additional trace output.  Sometimes useful to find out where things are going wrong in your test, particularly in complex Silverlight applications where wait timeouts occur unexpectedly.
waitCheckInterval WaitCheckInterval 500 Controls how frequently Wait operations polls for the condition to become true.
webAppPhysicalPath WebAppPhysicalPath String.Empty Must be set to the fully qualified physical path of an ASP.NET application when LocalWebServer is set to true.
Includes sample code including an example of App.config with default values for most settings.  I have set the baseUrl and modified TestBase to use settings.BaseUrl instead of the hard coded path used in my previous article.  I have also changed the LaunchNewBrowser call to the parameterless overload so that it relies on the defaultBrowser setting in the config file.
blog comments powered by Disqus

Tag cloud

Previous Articles