{"__v":3,"_id":"54ce0070584df10d00fe6998","category":{"__v":3,"_id":"54c51dbd1613c70d00eeacbe","pages":["54c521751613c70d00eeacc5","54ce0070584df10d00fe6998","54ce0c77fcc16f0d00f783fd"],"project":"54c51c5e2418480d0028a2c0","version":"54c51c5e2418480d0028a2c3","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-01-25T16:45:49.425Z","from_sync":false,"order":1,"slug":"configuration","title":"Configuration"},"project":"54c51c5e2418480d0028a2c0","user":"54c4b05742190d0d00f5fbde","version":{"__v":4,"_id":"54c51c5e2418480d0028a2c3","project":"54c51c5e2418480d0028a2c0","createdAt":"2015-01-25T16:39:58.382Z","releaseDate":"2015-01-25T16:39:58.382Z","categories":["54c51c5e2418480d0028a2c4","54c51da3796aed0d009fc80f","54c51db22418480d0028a2c9","54c51dbd1613c70d00eeacbe"],"is_deprecated":false,"is_hidden":false,"is_beta":false,"is_stable":true,"codename":"","version_clean":"1.0.0","version":"1.0"},"updates":[],"next":{"pages":[],"description":""},"createdAt":"2015-02-01T10:31:12.874Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":999,"body":"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. \n\n\tRun(Action<IAppConfigurator> configure)\n\nThis section will look at the methods available for configuring the web application that you are testing.\n\n## Project Location\nSeleno 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. \n\nSeleno provides two web server implementations:\n\n- **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.\n- **InternetWebServer**: Will point Seleno to a URL on the internet or your intranet.\n\n### IisExpressWebServer\nIf 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.\n\n\tInstance.Run(\"TestStack.Seleno.Samples.Movies\", 19456);\n\nThis 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.\n\n    var location = ProjectLocation.FromFolder(\"TestStack.Seleno.Samples.Movies\");\n    Instance.Run(configure => configure\n        .ProjectToTest(new WebApplication(location, 19456)));\n\nThis 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.\n\n### InternetWebServer\nIf 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.  \n\n\tInstance.Run(configure => configure\n    \t.WithWebServer(new InternetWebServer(\"www.google.co.uk\")));\n\nYou tell Seleno to use a custom web server, by calling the `WithWebServer` method of the configuration.\n\n### Custom Web Server\nIf you wanted to create a custom web server, then you would need to implement the `IWebServer` interface, specifying a `BaseUrl`.\n\n    public interface IWebServer : ILifecycleTask\n    {\n        string BaseUrl { get; }\n    }\n\nThe `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.\n\n    public interface ILifecycleTask\n    {\n        void Start();\n        void Stop();\n    }\n\n## Setting Environment Variables for the Web Application\nWhen 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.\n\nSeleno 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.\n\n\tInstance.Run(configure => configure\n\t    .WithEnvironmentVariable(\"FunctionalTests\")\n\t    .WithEnvironmentVariable(\"ConnectionString\", \"DefaultConnectionString\"));\n\n\nYou can read more about this topic in the following blog posts:\n\n- [Changing RunTime Behavior Of Application Under Test (Mehdi Khalili)](http://www.mehdi-khalili.com/changing-runtime-behavior-of-application-under-test#process-environment-variables)\n- [Black-Box Testing ASP.Net: Configuring Application Under Test (Michael Whelan)](http://www.michael-whelan.net/testing-mvc-configuring-application-under-test/)\n\n## Configuring Strongly Typed Navigation for ASP.Net MVC Applications\nSeleno 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.\n\nTo 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:\n\n    public class RouteConfig\n    {\n        public static void RegisterRoutes(RouteCollection routes)\n        {\n\t\t\t...\n\t\t}\n\nthen you could call `WithRouteConfig` and pass in the `RegisterRoutes` method:\n\n\tInstance.Run(configure => configure\n\t\t.WithRouteConfig(RouteConfig.RegisterRoutes)\n\n## HTML Control Naming\nSeleno lets you specify the naming strategy that it uses to identify control names. Seleno provies two HTML control ID generators\n\n- **DefaultControlIdGenerator**: Creates a sanitized ID with a valid HTML identfier, using the specified property name.\n- **MvcControlIdGenerator**: Uses the same algorithm ASP.NET MVC uses to generate control IDs.\n\nYou can specify the naming strategy that Seleno uses with the UsingControlIdGenerator method:\n\n    Instance.Run(configure => configure\n        .UsingControlIdGenerator(new MvcControlIdGenerator()));","excerpt":"","slug":"configuring-the-web-application","type":"basic","title":"Configuring the Web Application"}

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. ### IisExpressWebServer 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. ### InternetWebServer 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("www.google.co.uk"))); 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("FunctionalTests") .WithEnvironmentVariable("ConnectionString", "DefaultConnectionString")); You can read more about this topic in the following blog posts: - [Changing RunTime Behavior Of Application Under Test (Mehdi Khalili)](http://www.mehdi-khalili.com/changing-runtime-behavior-of-application-under-test#process-environment-variables) - [Black-Box Testing ASP.Net: Configuring Application Under Test (Michael Whelan)](http://www.michael-whelan.net/testing-mvc-configuring-application-under-test/) ## 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 .WithRouteConfig(RouteConfig.RegisterRoutes) ## 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()));