{"_id":"54c51f062418480d0028a2d2","version":{"_id":"54c51c5e2418480d0028a2c3","__v":4,"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"},"__v":1,"category":{"_id":"54c51da3796aed0d009fc80f","version":"54c51c5e2418480d0028a2c3","__v":2,"pages":["54c51eb5d4928c0d00d98e51","54c51f062418480d0028a2d2"],"project":"54c51c5e2418480d0028a2c0","sync":{"url":"","isSync":false},"reference":false,"createdAt":"2015-01-25T16:45:23.147Z","from_sync":false,"order":0,"slug":"introduction","title":"Introduction"},"project":"54c51c5e2418480d0028a2c0","user":"54c4b05742190d0d00f5fbde","updates":["5608d7e131beb60d001b654d"],"next":{"pages":[],"description":""},"createdAt":"2015-01-25T16:51:18.930Z","link_external":false,"link_url":"","githubsync":"","sync_unique":"","hidden":false,"api":{"results":{"codes":[]},"auth":"required","params":[],"url":""},"isReference":false,"order":1,"body":"1. Install-Package TestStack.Seleno\n\t* If you are using ASP.NET MVC then there are some helper methods for that which require you to install MVC if you want to use them: Install-Package Microsoft.AspNet.Mvc\n\t* If you installed MVC then you will also need to add binding redirects: Add-BindingRedirect\n\n2. Create a class that creates and holds a reference to an instance of SelenoHost. SelenoHost is your portal to Seleno. It does a lot of things, including running an IISExpress targeting the website you are testing, and as such is a relatively expensive class to instantiate for each test. So you create one instance and use it in your tests (unless you want to point Seleno at multiple websites or multiple browsers in which case you will need one instance per website and browser):\n\n\t\tpublic static class Host\n\t\t{\n\t\t\tpublic static readonly SelenoHost Instance = new SelenoHost();\n\n\t\t\tstatic Host()\n\t\t\t{\n                Instance.Run(\"Name.Of.Your.Web.Project\", 12346, c => c\n                    .UsingLoggerFactory(new ConsoleFactory())\n                    // If you are using MVC then do this where RouteConfig is the class that registers your routes in the \"Name.Of.Your.Web.Project\" project\n                    // If you aren't using MVC then don't include this line\n                    .WithRouteConfig(RouteConfig.RegisterRoutes)\n                );\n\t\t\t}\n\t\t}\n\t* The `123456` is the port number you want the site to run on - it can be anything you want, just make it unique and unused\n\t* The `c` variable is a fluent configurator - chain method calls off of it to configure the different parts of Seleno\n\t* By default it uses Firefox so you will need to install that\n\t* You might need to run Visual Studio / your test runner as an admin if you can an error when the port tries to get registered by IIS Express\n\n3. Create page objects by extending `Page`, or if you want to use strongly-typed view models, `Page<T>`, e.g.:\n\n        public class HomePage : Page\n        {\n            public Form1Page GoToRegisterPage()\n            {\n                return Navigate.To<RegisterPage>(By.LinkText(\"Register\"));\n            }\n        }\n        \n        public class RegisterPage : Page<RegisterModel>\n        {\n            public HomePage RegisterUser(RegisterModel registerModel)\n            {\n                Input.Model(registerModel);\n                return Navigate.To<HomePage>(By.CssSelector(\"input[type=submit]\"));\n            }\n        }\n\t* Seleno provides a DSL that hides most of Selenium Web Driver from you. Feel free to make use of intellisense within your page object to experiment with what's possible\n\t* There are some links to advanced usage instructions and tutorials below\n\n4. If you want to wrap common components of your pages then create components by extending `UiComponent`, e.g.:\n\n        public class HomePage : Page\n        {\n            ...\n    \n            public LoginPanel LoginPanel\n            {\n                get { return GetComponent<LoginPanel>(); }\n            }\n        }\n        \n        public class LoginPanel : UiComponent\n        {\n            public bool IsLoggedIn\n            {\n                get { return Find.OptionalElement(By.Id(\"login-panel\")) == null; }\n            }\n    \n            public string LoggedInUserName\n            {\n                get { return Find.Element(By.Id(\"login-username\")).Text; }\n            }\n        }\n\n5. Create automated tests that use your page objects, e.g. this NUnit example:\n\n        class RegistrationTests\n        {\n            [Test]\n            public void GivenAUserIsntRegistered_WhenRegisteringThem_TheyEndUpBackOnTheHomepageAndLoggedIn()\n            {\n                var page = Host.Instance.NavigateToInitialPage<HomePage>()\n                    .GoToRegisterPage()\n                    .RegisterUser(ObjectMother.NewUser);\n    \n                Assert.That(page.Title, Is.EqualTo(\"Home\"));\n                Assert.That(page.LoginPanel.IsLoggedIn, Is.True);\n                Assert.That(page.LoginPanel.LoggedInUserName, Is.EqualTo(ObjectMother.NewUser.UserName));\n            }\n        }","excerpt":"","slug":"getting-started-with-seleno","type":"basic","title":"Getting Started with Seleno"}

Getting Started with Seleno


1. Install-Package TestStack.Seleno * If you are using ASP.NET MVC then there are some helper methods for that which require you to install MVC if you want to use them: Install-Package Microsoft.AspNet.Mvc * If you installed MVC then you will also need to add binding redirects: Add-BindingRedirect 2. Create a class that creates and holds a reference to an instance of SelenoHost. SelenoHost is your portal to Seleno. It does a lot of things, including running an IISExpress targeting the website you are testing, and as such is a relatively expensive class to instantiate for each test. So you create one instance and use it in your tests (unless you want to point Seleno at multiple websites or multiple browsers in which case you will need one instance per website and browser): public static class Host { public static readonly SelenoHost Instance = new SelenoHost(); static Host() { Instance.Run("Name.Of.Your.Web.Project", 12346, c => c .UsingLoggerFactory(new ConsoleFactory()) // If you are using MVC then do this where RouteConfig is the class that registers your routes in the "Name.Of.Your.Web.Project" project // If you aren't using MVC then don't include this line .WithRouteConfig(RouteConfig.RegisterRoutes) ); } } * The `123456` is the port number you want the site to run on - it can be anything you want, just make it unique and unused * The `c` variable is a fluent configurator - chain method calls off of it to configure the different parts of Seleno * By default it uses Firefox so you will need to install that * You might need to run Visual Studio / your test runner as an admin if you can an error when the port tries to get registered by IIS Express 3. Create page objects by extending `Page`, or if you want to use strongly-typed view models, `Page<T>`, e.g.: public class HomePage : Page { public Form1Page GoToRegisterPage() { return Navigate.To<RegisterPage>(By.LinkText("Register")); } } public class RegisterPage : Page<RegisterModel> { public HomePage RegisterUser(RegisterModel registerModel) { Input.Model(registerModel); return Navigate.To<HomePage>(By.CssSelector("input[type=submit]")); } } * Seleno provides a DSL that hides most of Selenium Web Driver from you. Feel free to make use of intellisense within your page object to experiment with what's possible * There are some links to advanced usage instructions and tutorials below 4. If you want to wrap common components of your pages then create components by extending `UiComponent`, e.g.: public class HomePage : Page { ... public LoginPanel LoginPanel { get { return GetComponent<LoginPanel>(); } } } public class LoginPanel : UiComponent { public bool IsLoggedIn { get { return Find.OptionalElement(By.Id("login-panel")) == null; } } public string LoggedInUserName { get { return Find.Element(By.Id("login-username")).Text; } } } 5. Create automated tests that use your page objects, e.g. this NUnit example: class RegistrationTests { [Test] public void GivenAUserIsntRegistered_WhenRegisteringThem_TheyEndUpBackOnTheHomepageAndLoggedIn() { var page = Host.Instance.NavigateToInitialPage<HomePage>() .GoToRegisterPage() .RegisterUser(ObjectMother.NewUser); Assert.That(page.Title, Is.EqualTo("Home")); Assert.That(page.LoginPanel.IsLoggedIn, Is.True); Assert.That(page.LoginPanel.LoggedInUserName, Is.EqualTo(ObjectMother.NewUser.UserName)); } }