Automated UI Testing with Seleno
Mark Nischalke Over 19 years of experience in full lifecycle software development, from analysis and requirements gathering to design, development and deployment. Architected and designed solutions for Fortune 100 companies and smaller organizations spanning a number of different industries. Solutions have utilized a variety of technologies, including Azure, ASP.NET, ASP.NET MVC, SharePoint, JavaScript, and Microsoft SQL Server. Experienced Solution Architect, manager, team lead, mentor, trainer and Project Manager, with training from the Project Management Institute. Microsoft certifications including MCPD, MCSD, MCAD, MCSA and MCTS www.mansoftdev.ccom mark@mansoftdev.com
Agenda What is Unit Testing? What is UI Testing? Selenium web browser automation Seleno with MVC Demo Q&A
What is Unit Testing? Exercising code base to ensure quality Multiple frameworks NUnit MS Test [TestClass] public class FooTest { [Test Method] public void Foo_HappyPath_Test() Foo sut = new Foo(); var actual = sut.GetBar(); Assert.IsNotNull(actual); }
What is UI Testing? Testing page elements Ensuring page level logic Textboxes, buttons, validations Ensuring page level logic Elements shown/hidden Proper ranges set Problems Manual process Error prone Time consuming Tedious
Selenium Suite of tools to automate web browsers Java-based Open source WebDrivers Chrome IE Firefox Safari IDE as Firefox add-in
Selenium // Initialize the Chrome Driver using(var driver = new ChromeDriver()) { // Go to the home page driver.Navigate().GoToUrl("http://myapp/login"); // Get the page elements var userNameField = driver.FindElementById("userName"); var userPasswordField = driver.FindElementById("password"); var loginButton = driver.FindElementByXPath("//input[@value='Login']"); // Type user name and password userNameField.SendKeys("admin"); userPasswordField.SendKeys("12345"); // and click the login button loginButton.Click(); }
Seleno Distributed by TestStack Uses Selenium Strongly typed view models Page Objects
Seleno Page Objects The usage of the Page Object design pattern creates a strong separation of concerns between tests and Page Objects. The tests specify what should happen and the Page Objects encapsulate how it happens. Page Objects encapsulate all of the interaction with Selenium, and all of the logic of that interaction.
Demo project …FINALLY, CODE
Q & A
References Sample and article http://www.mansoftdev.com/blog https://github.com/marknisc/Seleno mark@mansoftdev.com Seleno http://seleno.teststack.net SeleniumHQ http://docs.seleniumhq.org/