5.9. More WatiN Examples

The previous section should have provided you with an insight into how you can successfully structure and get started writing your UI automation tests.

Following this, we wanted to provide some more examples for UI tests around the sample application and show how you can structure tests around an application.

Depending on how your application is structured will depend on how you need to test certain parts. With this sample application, there is a linear approach to how users would walk though the application. As such, this is how the tests need to be performed. In other applications, you could go directly to particular parts of the application by using the appropriate URL and begin testing from there.

Based on how the application is structured, there still needs to be a product in the database for us to work with. If we wanted to verify how the shopping cart behaves, then we first need to add an item to the shopping cart. This is one example of why having a centralized Product Builder allows us to reuse the logic and structure for inserting our test data, as shown below.

public override void DataCreation()
{
    Product product = new ProductBuilder()
        .WithName("p1")
        .WithDescription("d1")
        .InCategory("category")
.WithBasePrice(1.00);

    ProductRepository repository = new ProductRepository(DbConfig);
    repository.SaveOrUpdate(product);
}

With the test data in place, we can reuse our ProductsMenuPage model and abstraction to control and interact with the page. Because ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.