Using the HTTP Proxy
Telerik Testing framework includes the ArtOfTest.WebAii.Messaging.Http namespace. With it you have the ability to intercept raw HTTP traffic under the cover. Using the HTTP proxy you can intercept an HTTP request originating from the browser before it is sent to the web server and/or intercept HTTP responses coming from the web server just before they reach the browser and are rendered by it. This functionality opens up the framework to be used in a wider range of automation scenarios like:
Security Testing: In your listener you have access to all the basic HTTP Request/Response properties and you can examine, inject, alter or do whatever you want with them.
Performance Testing: You can use the HTTP listeners to look at file sizes you are sending or receiving and even build regression unit tests that make sure your files don't grow beyond a certain size.
Page Synchronization: You can now sync your test to specific requests and have the ability to detect Ajax requests over the wire. We plan to add more extended object modeling for this.
In this namespace you will find the following methods classes:
Class | Description |
---|---|
HttpProxyManager | Manages the HTTP proxy agent. |
HttpRequest | Used to create and manipulate an HTTP request. |
HttpRequestEventArgs | EventArgs subclass that wraps an HTTP request, and possibly the related response. |
HttpResponse | Class wrapper of an HTTP response. |
HttpResponseEventArgs | EventArgs subclass that wraps an HTTP response and the related request. |
RequestListenerInfo | Wraps a listener for BeforeRequest events from the proxy. |
ResponseListenerInfo | Wraps a listener for BeforeResponse events from the proxy. |
You must enable the HTTP proxy before you can start using it. This setting is turned off by default. This can be done either by adding the setting to your .config file or modifying the setting in the Settings object. To add the setting to your .config file add this to your .config file:
To enable this setting in the Settings object, add code to your initialization section like this:
Now that we have the HTTP proxy turned on we can start using it. Here's an example of how we would detect that a response coming back from the web server is an image response.
Let's go one step further. Suppose we want to verify that all of the images on the web page were smaller than 40Kb. We can accomplish this using code like this:
Note: If you are using localhost in the URL of the NavigateTo method it must contain a trailing '.' character like this: ActiveBrowser.NavigateTo("http://localhost./myTestPage") . This is an IE limitation where all URL's must contain a '.' character in them to be recognized properly when a proxy is in place.