Chapter 6. Advanced Web Testing

This chapter is a continuation of the previous chapter, which explained web performance testing in detail including the recording and running of a testing scenario based on user actions. There is another way of performing the same web test using Visual Studio: by generating code from the action recording using the Generate Code option in the Web Performance Test toolbar. The coded web performance test is the .NET class that generates the sequence of web requests in the order they were recorded. The class can be written in C# or Visual Basic.

It is possible to create such code by creating a new class file and using the namespace Microsoft.VisualStudio.TestTools.WebTesting, which contains all classes required for creating the web performance test. However, it is too complex to create the test manually, compared to generating the code from the recording. Therefore, it is suggested practice to convert the recorded web performance test. The testing is the same whether it is done using the generated code or through normal web testing using the user interface; the advantage is the flexibility of customizing the test by using the .NET framework language. The generated code can be modified using the language to add looping, conditions and branching, and also to add more requests and to remove existing requests.

This chapter concentrates on explaining how to generate code from a recorded test and then customizing it. The different sections within this chapter cover the following topics:

  • Generating code from a recorded test
  • Adding transactions and comments
  • Debugging a coded web test
  • Adding custom rules to the test

Dynamic parameters in web testing

Most web applications generate data dynamically and send it via query string parameter or form post parameter to subsequent requests. The current user session ID, connection string, or parameter values to the called method are examples of dynamic data. Web performance testing can identify and detect these dynamic parameters from the request response and then bind it to other requests. This process is also known as promoting dynamic data to dynamic parameters.

Dynamic parameters are automatically detected by the web performance test after the web test recording is completed. Visual Studio web testing keeps track of the requests and finds the hardcoded values, which can be replaced by dynamic parameters. The advantage of using dynamic parameters is it enables us to pass different values to the parameters and verify the test. The other reason is it lets us avoid playback failures. If the recorded values are not promoted as dynamic parameters, the playback of the test may fail as the values would stay static (as they were captured during the recording and may not satisfy the current test conditions).

Once the web test recording is complete, Visual Studio provides the ablity to extract values from the request and replace them with the parameters. This is the same extraction rule that is explained in Chapter 5, Web Performance Test which is about web performance test. But in this case, they are automatically added by the web test. At the same time, the parameters are also added to subsequent requests.

For example, the following screenshot shows the recording of a website, which has links to the employee and emergency contacts pages, by passing the query strings and the session ID (which changes every time the test is run).

Dynamic parameters in web testing

When the recording is stopped, we can see the dialog saying Detecting dynamic parameters.... During this time, all the values that can be changed to a web test parameter are detected and listed.

Visual Studio lists the parameters that can be promoted to web test parameters from normal hardcoded values, and allows the tester (who is recording the test) to choose one. We can either choose OK to promote the parameters, or we can Cancel the suggestion and keep it hardcoded.

Note that if we leave the parameters as is, the next playback of the test might fail because the hardcoded value may not be valid.

Visual Studio also provides the option of detecting dynamic parameters outside the recording, which means that there is an option in the toolbar to promote the parameters after the completion of recording as well.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.249.198