Test run: Use Windows PowerShell for request/Response testing

Source: Internet
Author: User
Tags http request

The most basic WEB test format is the HTTP request/response test. This involves sending an HTTP request to a WEB application programmatically, extracting an HTTP response, and checking whether the response is the expected value.

There are a number of options available if you need to perform request/response testing for asp.net applications. You can write C # or Visual basic® console applications. You can also write JavaScript or Perl scripts. If you have a high starting point, you can write a C + + program. Windows powershell™ can now also be used in this area.

I've used many of these techniques, and Windows PowerShell has become the preferred method for me to perform lightweight HTTP request/Response testing. Just write a small Windows PowerShell script that allows it to programmatically publish information to a asp.net application on a Web server, and everything will be all right. The script then retrieves the HTTP response and checks to see if it is the expected value, determining whether the result is passed or failed.

In this month's column, I'll show you how to use Windows PowerShell to perform request/response testing against asp.net applications. I assume you have at least some basic knowledge of asp.net and Windows PowerShell. However, even if you have not contacted these topics before, you can still effortlessly understand what I am talking about.

Figure 1 is a simple but very representative asp.net Web application called Minicalc. As you can see, the MINICALC application accepts two integers, calculates their totals or products, and displays results that include four decimal places. The actual WEB application is much more complex than this simple sample application, but the technology I am introducing can easily be extended to more complex applications.

Figure 1 Simple asp.net Web application to test

Figure 2 shows the running Windows PowerShell test script. For simplicity, I used hard coding to process all the information associated with the application to be tested. I'll explain how to parameterize this script later. The script first echoes the target URL http://localhost/MiniCalc/Default.aspx, and then probes the initial ViewState and eventvalidation values of the requesting WEB application. They are key values that I will explain later.

Figure 2 Windows PowerShell test script in Run

Next, the script publishes the information programmatically, simulates the user typing 5 into TextBox1, TextBox2 3, selects RadioButton1 (the addition operation), and then clicks Button1 (performs the calculation). The script captures the HTTP response from the WEB server, displays the entire response, and then searches the response to see if 8.0000 (5 + 3 results) are displayed in the TextBox3 (the control that was created to display the calculated results).

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.