Configuring the Web Application

When you initialise Seleno, by calling the Run method on your SelenoHost instance, you are able to configure Seleno by calling actions on the IAppConfigurator interface.

Run(Action<IAppConfigurator> configure)

This section will look at the methods available for configuring the web application that you are testing.

Project Location

Seleno needs to know where the web application you are testing is located. To do this, it uses the concept of a web server to define the location of the web application.

Seleno provides two web server implementations:

  • IisExpressWebServer: Will host an ASP.Net MVC/WebForms application, located in a folder on the same machine, in an IIS Express process. It requires IIS Express to be installed. This is the default web server.
  • InternetWebServer: Will point Seleno to a URL on the internet or your intranet.


If your web application is a project in the same solution as your Seleno project, then you can simply initialise Seleno with the name of the folder and the port for IIS Express to host it. If the folder cannot be found in the solution then a DirectoryNotFoundException is thrown.

Instance.Run("TestStack.Seleno.Samples.Movies", 19456);

This method will use the ProjectLocation class to create a WebApplication with a valid folder and port number. If you want more control over the creation of the WebApplication then you can use the ProjectToTest configuration method to pass in a WebApplication you construct yourself.

var location = ProjectLocation.FromFolder("TestStack.Seleno.Samples.Movies");
Instance.Run(configure => configure
    .ProjectToTest(new WebApplication(location, 19456)));

This would be useful if the web application was not in a sub-folder of the solution. In that case, you could just create the location using the ProjectLocation.FromPath("some path") method and passing in the full path to the folder containing the web application.


If your web application is available via a URL, then you do not need to host it in IIS Express. Instead, you just configure Seleno to use an InternetWebServer, passing in the URL.

Instance.Run(configure => configure
	.WithWebServer(new InternetWebServer("")));

You tell Seleno to use a custom web server, by calling the WithWebServer method of the configuration.

Custom Web Server

If you wanted to create a custom web server, then you would need to implement the IWebServer interface, specifying a BaseUrl.

public interface IWebServer : ILifecycleTask
    string BaseUrl { get; }

The IWebServer interface itself implements the ILifecycleTask, so in addition you would also have to implement its Start and Stop methods for starting and stopping the web server.

public interface ILifecycleTask
    void Start();
    void Stop();

Setting Environment Variables for the Web Application

When you create a process to host your ASP.Net web application you are able to pass in environment variables as key/value pairs. Your application code can then check for these variables and choose different configuration behaviour depending on the value of the variable.

Seleno provides the WithEnvironmentValue method on the configurator. This allows you to pass in a key/value pair, or just the key. You need to call the method for each environment variable that you want to add.

Instance.Run(configure => configure
    .WithEnvironmentVariable("ConnectionString", "DefaultConnectionString"));

You can read more about this topic in the following blog posts:

Configuring Strongly Typed Navigation for ASP.Net MVC Applications

Seleno is able to generate URLs from controller actions for MVC applications using the application's route table. This removes the brittleness of URLs from your tests as they will always be in sync with those that the application is using.

To tell Seleno what routes to use, just pass an Action<RouteCollection> to the WithRouteConfig method. For example, if your MVC application defines its routes in a RouteConfig class, with a RegisterRoutes method:

public class RouteConfig
    public static void RegisterRoutes(RouteCollection routes)

then you could call WithRouteConfig and pass in the RegisterRoutes method:

Instance.Run(configure => configure

HTML Control Naming

Seleno lets you specify the naming strategy that it uses to identify control names. Seleno provies two HTML control ID generators

  • DefaultControlIdGenerator: Creates a sanitized ID with a valid HTML identfier, using the specified property name.
  • MvcControlIdGenerator: Uses the same algorithm ASP.NET MVC uses to generate control IDs.

You can specify the naming strategy that Seleno uses with the UsingControlIdGenerator method:

Instance.Run(configure => configure
    .UsingControlIdGenerator(new MvcControlIdGenerator()));