Using Watin for TDD

Source: Internet
Author: User
Tags assert

These two days have heard a very good based. NET platform of the Web Automation test framework watin, download a trial, really good use. Its basic functions and selenium a bit like, but not as strong as selenium, no script recording, only support IE6/7 and so on. Its basic functions include automating most of the HTML elements, finding ways to support Ajax, supporting Frame/iframe, supporting pop-up boxes, and more. Now let's take a simple example to see how to use Watin for TDD.

In this example, a function based on the Northwind database is used to find a customer by ID, list the relevant basic information, and then be able to find all the order associated with it. Let's do it one step at a time. (development tool is Visual Studio 2008 Beta2, test framework includes NUnit and Watin)

(recall several steps of test-driven development: Write test--> test failure--> Write implementation--> test--> Repeat code for refactoring--> repeat)

Here I put the above function into two steps to achieve: 1. Find Customer and list information if found. 2. Find the associated order. The first section is implemented first:

Think about what controls the page needs, an input box to enter the customer ID, a button to find the action, click the button, and if you find the customer, list his ID and his company Name.

[TestFixture]
  public class FindCustomerAndOrders
  {
    [Test]
    public void ShouldFindCustomer()
    {
      IE ie = new IE("http://localhost:1781/Default.aspx");

      ie.TextField(Find.ById("tb_customerID")).TypeText("ALFKI");
      ie.Button(Find.ById("btn_find_customer")).Click();

      Assert.That(ie.ContainsText("ALFKI"), Is.True);
      Assert.That(ie.ContainsText("Alfreds Futterkiste"), Is.True);

      ie.Close();
    }

  }

To explain briefly, first create an IE, enter the page, and then look for the id "tb_customerid" text box, enter the text "ALFKI", and then look for the button ID "Btn_find_customer" and click. The next two assertions indicate that the page should have a "ALFKI" that is the customer ID and "Alfreds futterkiste" that is the customer's company Name. Finally, close ie.

Run the test, because the page has not yet been created, the test is obviously not passed. The error message is that the text box is not found

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.