Monday, 26 July 2010

Parametrising server address

The final touch to the script would be to parametrize server address so that one script could be run against different environments. This could be very handy if the scripts needs to be recorded before the application is deployed to the production (or copy of production) environment where it is to be performance tested.

Depending on the environment configuration the difference between URLs could be:

  • web server hostname/IP address
    Environment1: http://development
    Environment2: http://staging
  • port number
    Environment1: http://application:8080
    Environment2: http://application:7800
  • context path
    Environment1: http://application/inc10
    Environment2: http://application/inc11
  • or any combination of the above

The first scenario (different hostname or IP address) is by far more common. It is also very easy to configure in WebTest using "Parameterize Web Servers" button in the WebTest tool bar. The same approach will also work for the second case where the application server hostname and/or port is different between both environments.

WebTest context parameter
As the result of this web server URL in the whole script is replaced with parameter and new Context Parameter is automatically added to the WebTest.

It is best to keep parameter name generic (i.e. DevWebServer is a bad name since it won't be valid once URL is replaced with one pointing to Staging environment).

In case the difference between environment is reflected by different context path (e.g. http://application/ContextPath) server address parametrization cannot be done in a simple way as above.
Since I always tend to avoid doing thinks manually (which could be time consuming and error prone) I had to find another way of doing this. The easiest way I found was via editing WebTest as a XML document and running search and replace on the application address.

Name of the parameter which will replace server address would be the name of the context parameter containing application URL which would need to be created manually. This can be done by right clicking on  the WebTest parent node and selecting "Add Context Parameter" from the context menu.
If the name of the context parameter which contains server address is ApplicationServer then server address should be replaced with {{ApplicationServer}} and the exact text which is being replaced should be set as a value of this context parameter.

This approach will work with any combination of the three URL parts (address, port and context path).

As a final note please remember that web address parametrisation should only be used if both environments have exactly the same version of the application deployed.

No comments:

Post a Comment