5.14. Applying Automated UI Testing to the ASP.NET Family

You have learned that UI tests that are tightly coupled to the browser become hard to read and maintain if there are changes made to the application under test, and tests should be abstracted as far away from the browser as possible. The following section is intended to apply some of the techniques discussed in this chapter to specific technologies that fall under the ASP.NET family.

5.14.1. ASP.NET WebForms

The techniques that abstract the tests from the browser that have been discussed so far are all valid when testing against ASP.NET WebForms. Problems will occur if you are testing ASP.NET WebForm applications where the data access is not abstracted very well. The following example contains a set of tests to ensure a user can log in to a homepage of an order-processing system. You cannot tell from these tests that the application is using ADO.NET to return datasets to the WebForms to render the data:

using NUnit.Framework; using WroxPizza.Orders.Tests.Integration.model; namespace WroxPizza.Orders.Tests.Integration { public class HomePageTests: BaseUITest { [Test] public void Should_Load_Load_The_Home_Page() { HomePage homePage = new HomePage(Browser); string expectedTitle = "wrox pizza shop | login"; Assert.AreEqual(expectedTitle, homePage.Title.ToLower()); } [Test] public void Should_Not_Login_With_An_Invalid_User() { HomePage homePage = new HomePage(Browser); homePage.LoginUser("Invalid_User_Name", "Invalid_Password"); ...

Get Testing ASP.NET Web Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.