Online Book Reader

Home Category

Programming Microsoft ASP.NET 4 - Dino Esposito [193]

By Root 5254 0
= ...;

webServer.StartInfo.Arguments = String.Format(

"/port:8080 /path: {0}", path);

webServer.Start();

}

[TestMethod]

public void CheckIfNicknameIsNotUsed()

{

using (IE ie = new IE("http://localhost:8080/Samples/Datagrid"))

{

// Select a particular customer ID

ie.SelectList("ddCustomerList").Option("1").Select();

// Check the resulting HTML on first row, second cell

Assert.AreEqual(

"A Bike Store",

ie.Table(Find.ById("gridOrders").TableRow[0].TableCells[1].InnerHtml));

}

}

[TestCleanup]

public void TearDown()

{

webServer.Kill();

}

}

The testing tool triggers the local Web server and points it to the page of choice. Next, it simulates some user actions and checks the resulting HTML.

Different tools might support a different syntax and might integrate with different environments and in different ways. However, the previous example gives you the gist of what it means to test the front end.

Web UI testing tools can be integrated as extensions into browsers (for example, Firefox), but they also offer an API for you to write test applications in C# or test harnesses using MSTest, NUnit, or other test frameworks. Table 8-7 lists a few popular tools.

Table 8-7. Tools for Testing a Web Front End

Tools

More information

ArtOfTest

http://www.artoftest.com/home.aspx

Selenium

http://seleniumhq.org

Visual Studio 2010 Coded UI Tests

http://msdn.microsoft.com/en-us/library/dd286726.aspx

WatiN

http://watin.sourceforge.net

Testing Posted Data


In ASP.NET MVC, testing the actual behavior of code-behind classes is relatively easy if you refactor the code to take that code out to a controller or a presenter. However, each method you test is expected to receive a bunch of parameters, either through the signature or via ASP.NET intrinsic objects.

How can you test that the browser really passes in correct data? In other words, how can you test posted data.

Sending automated POST requests to a URL is a feature that all the tools in Table 8-7 support. They all let you fill in and post a form. However, in that case, at least, the local Web server must be up and running. Posting to test pages that do nothing but return a Boolean answer (expected/unexpected) is a possible way to speed up things.

If you want to simply look at what is being transmitted, you can turn your attention to tools such as Fiddler (http://www.fiddler2.com/fiddler2) or HttpWatch (http://www.httpwatch.com).

Note

ASP.NET Web Forms was not designed with testability in mind. You can still test Web pages but at the cost of spinning up the entire ASP.NET runtime; or, more likely, you will reduce your efforts to just testing what’s strictly necessary at the code-behind level. The tools in Table 8-7 address, instead, the need to test the client user interface and simulate user actions that result in posted data.

Summary


A Web page is a special type of a standalone component that has the additional tricky requirement of being able to work with the rest of the site. Amazingly, this generates a bunch of extra work because developers, architects, and designers must cooperate to produce a common and appealing look and feel, ease of maintenance, consistent rendering, navigation capabilities, and personalization capabilities. All around, there’s room for a new professional with ad hoc and somewhat unique skills, such as Web testers and SEO and usability experts.

A successful Web site results from a usable composition of pages, which in turn result from a consistent composition of UI blocks. In this chapter, we first reviewed the technologies for page composition that you find available in ASP.NET (primarily, master pages), and then we moved toward other side topics, such as cross-browser rendering, search-engine optimization navigation, and UI testing.

In the next chapter, we’ll complete the basics of the Web page by looking at input forms.

Chapter 9. ASP.NET Input Forms


It’s not enough that we do our best; sometimes we have to do what’s required.

—Winston Churchill

Although formless pages are still accepted

Return Main Page Previous Page Next Page

®Online Book Reader