| ProfileVisual Studio Team Test ...BlogLists | Help |
Visual Studio Team Test - Starting OutBecause Manual Testing Bores us to Death! October 12 Must Read VSTS - Testing Related Blogs and Introductory Articles
Must Read VSTS - Testing Related Blogs and Introductory Articles Some excellent resources to get up and running with web and load tests. I’ve selected the posts which should be easy to understand for people getting started with VSTS – Test Edition. These are the things you will run into if you are writing a production test. Please go ahead and check out the blogs for more advanced posts. http://blogs.msdn.com/slumley/ Custom Data Binding in Web Tests Load Testing Web Services with Unit Tests ASP.Net Load Test Maintenance App
http://blogs.msdn.com/joshch/default.aspx
Custom ExtractionRule to extract form fields by index A custom ValidationRule to catch redirects to error pages Creating custom IHttpBody classes for coded web tests Web Test Authoring and Debugging Techniques
http://blogs.msdn.com/billbar/ Article Posted: What is the data in the load test results store Article Posted: Advanced Load Testing Features of VSTS
http://blogs.msdn.com/vstsloadtestblog
Entries we have posted so far – Getting Started with Web Tests in VSTS - Tracking AJAX Calls Web Test : Adding A Client and Testing if it Appears in a Grid Custom Validation Rule - Validation for empty field Fiddler Save as Web Test Vs Web Test Recorder Custom Extraction Rule and Generating a Code Test from VSTS
Custom Extraction Rule and Generating a C# Code Test We swear by the fantastic dinner we had last night(Thank you Rohit, who got bullied into giving us a dinner treat), extracting the client ID to get Client’s Test Cases working was a tough one. The issue we faced for retrieving the client ID: The client data was bound in a grid cell, with the cell data having a hyperlink to open the details for the client. And we found no hidden field to extract this value from. We found no other way but to write the HTML tag parser based on the current structure within the project.
This is what we wrote and thought we had it done. We had the client ID.
Extracting the Client ID from the Responce HTML
45 public override void Extract(object sender, ExtractionEventArgs e) 46 { 47 if (e.Response.HtmlDocument != null) 48 { 49 string clientID = ""; 50 foreach(Microsoft.VisualStudio.TestTools.WebTesting.HtmlTag tag in e.Response.HtmlDocument.HtmlTags ) 51 { 52 if(tag.Name=="a") 53 { 54 foreach (Microsoft.VisualStudio.TestTools.WebTesting.HtmlAttribute attr in tag.Attributes) 55 { 56 if (attr.Name=="href" && attr.Value.Contains("clientID=")) 57 { 58 string[] attrValue = attr.Value.Split(new char[] {'='}); 59 clientID= attrValue[1]; 60 } 61 } 62 } 63 } 64 65 if (clientID != string.Empty) 66 { 67 e.WebTest.Context.Add(ContextKey.ClientID, clientID); 68 m_clientID = clientID; 69 } 70 71 } 72 } This is how we add custom extractor with any step:
Now we needed this to be passed further in the query parameters. So we made another method to get the current web context and update the client ID parameter in the current context. This is the code for the class. Here we have used the Extract class to serve the purpose. That is why the whole logic has been implemented in the override of the Extract method.
74 // The Extract method. The parameter e contains the Web test context. 75 // Here we have override this method to replace the client ID in the context 76 public override void Extract(object sender, ExtractionEventArgs e) 77 { 78 if (!(e.Response.IsHtml)) 79 { 80 e.Success = false; 81 e.Message = "The response did not contain HTML."; 82 return; 83 } 84 85 string clientID = e.WebTest.Context.Item(ContextKey.ClientID).ToString(); 86 87 foreach (QueryStringParameter param in e.Request.QueryStringParameters) 88 { 89 if (param.Name == "clientID") 90 { 91 param.Value = clientID; 92 } 93 } 94 e.Success = true; 95 } But there was another problem now. We had extracted the client ID but had no way to update the query parameter for the next pages. How do we do that? We experimented but to no avail. Our mind running harder (running at 7200 rpm) but we could not see a way to achieve this by web test. Welcome Code Test…. We generated the code from the web test and worked on it. You can generate the code test by doing a right click on the web test and selecting “Generate Code…” from the options. One Click Code Generation Option !
Once the code is generated, it can be modified as any other C# Class. We do need to think about maintainability at this point. We are working at an architecture of having a partial class in which we will write our custom rules and let the generated one be overwritten every time. This is one of the requests from the web test as in the code format. Now we had the code in hand and also the client ID. This data was passed on to the further query parameters and everything worked fine. This is how we used it. To run a code test you need to follow the following steps:
This code test seemed to be a good way of sorting out things in our test cases context. It would have maintainibily issues - as we generate the code again later. We will tackle those in the coming posts. Iqbal and Rohit signing off on day three Use web test context to pass data between wizard screens.
Use web test context to pass data between wizard screens. In this post, we will discuss about passing parameters across wizard screens by saving them in the web test context. Here we will take the example of adding a new project in the Projects123 application. In this we will follow the following steps
Step 1: Add the phase of the project. When the user goes to second step, we save the values of the first screen in the web test context.
Quick look in the Web Test Context Items: The Web Test Context is not filled with any of the value as shown below.
Step 2: Add Project Description On the initialization of second panle of the wizard, the first screen values are posted in the web test context.
Quick look at the web test context parameters: The values are visible in the screen. How to add/extract values from the web test context Add parameter in context 43 /// <summary> 44 /// This method adds the specified parameter and its value in the web test context. 45 /// </summary> 46 /// <param name="e">Web Test Context </param> 47 /// <param name="parameter">Key of the item to be saved in the context</param> 48 /// <param name="parameterValue"></param> 49 private void AddWebContextValue(ExtractionEventArgs e, string key, string value) 50 { 51 e.WebTest.Context.Add(key, value); 52 } Extract parameter from context 54 /// <summary> 55 /// This function is extracts a value from the web context with the specified key. 56 /// </summary> 57 /// <param name="e">Web Test Context</param> 58 /// <param name="parameter">Key of the item to be extracted from the context</param> 59 /// <returns> value of the context item</returns> 60 private string GetWebContextValue(ExtractionEventArgs e, string key) 61 { 62 string value = ((string)(e.WebTest.Context.Item(key))); 63 System.Diagnostics.Debug.Assert(value); 64 return value; 65 }
Fill the values required for the second screen of the wizard.
Step 3 – Add Description This is the last step in the wizard. So here we will view the parameters of the last two screens in the web test context.
Quick look at the Web Test Context: Values of both the wizard screens are visible here.
With above discussion we can easily manage and pass the data between various test stages. In our next post, we will try to confirm the values that are added through a wizard in the application. - Manav and Kay October 11 Fiddler Save as Web Test Vs Web Test Recorder
Putting Blind Faith on Fiddler “Save as Web Test” Feature and Paying for it
The second day of our week long date with VSTS – Team Test, happened to be even more exciting. The day began with the in-house birthday celebration (Rohit turned 24). We wished him and sang him a song in exchange for a dinner from his end. The Projects123 team(The AJAX ASP.Net App we are writing test cases for), already had their scripts written in WATIR. We started analyzing them – so we could concentrate on the VSTS features rather than the business rules. Test Case : Add a Team Members from a ASP.Net Wizard and check if the Values were visible in the application.
We wanted to test if a team member was added successfully and if the values were visible in the grids and the forms. With the confidence we had from the earlier implementation, we knew it was just a matter of hours before we were to start on the validations. We had tested an insert with a Form View. We generated the web tests from the fiddler calls (See this post for details). First Team Member added through the ASP.Net Wizard – took 5 minutes. WOW! We just changed the values for another test run, and went for it. Our Team Member number 2 added. Wait! The name was changed to “Marie Pierce” but we were still seeing the earlier name “Martha Mitchelle”. We tried again – with different values – but each time we saw the values from our first run being saved to the database.
Two hours and we were into the same issue. Where we going to have a sad birthday party?! Surely our mind would still be here … unless we find out what’s going on. One thing was for sure that all this had to do with the wizard thing. We had earlier added a Client using a Form View successfully. Ok so trying on some another wizard seemed an option and we started off on Add Project. With the test generation and re-run, the issue appeared there too. So the whole wizard thing caused the problem. MSDN - About JavaScript and ActiveX Controls in Web Tests - http://msdn2.microsoft.com/en-us/library/ms404678.aspx says - The disadvantages of Fiddler are that it does not currently support SSL, it does not automatically track hidden fields, such as ViewState, and it does not filter out dependent requests. AH! All the while we have using the Fiddler session calls to make our web tests. It was the most practical thing to do as the built recorder missed the AJAX Calls. So we went ahead and used the web test recorder for recording this test. HOLA – things worked perfectly! To give a real explanation, this is what really happened. We generated the session calls from Fiddler, which looks like this: Fiddler Generated Calls
When we look at the _VIEWSTATE value, we find that the value has been encrypted. Fiddler is a tool which captures the session calls and generates the view state for the data. So when “Martha Mitchell” was being added (for the first time), the view state had the value for this. It was maintained for the data we changed, and so that was the problem. Now let us see how it was solved by the Web test recorder. This is what we get from the web recorder. Web Test Recorder Generated Calls
Here the _VIEWSTATE is dynamically binded and is in the hidden state. This means that the controls are binded with the view state with some values (typically called myparams). So when the data was changed in the control, the myparam value was changed, so the view state got updated. This resulted to maintain the new values for the controls and save what we wanted. Summing up the difference: The web context was dynamically updated for the web recorded calls but not by the fiddler calls And this is what we got with just changing the recorded calls’ values. Test Case Passed - Multiple Values Persisted Successfully Lesson Learnt – Use a combination of Fiddler and Web Recorder while writing tests. Use Fiddler for AJAX Calls/JavaScript and Web Recorder for everything else. See you tomorrow! – Iqbal & Rohit October 10 Custom Validation Rule - Validation for empty field
Custom Validation Rule - Validation for empty field
Second day on the getting started with VSTS week, we will try to ‘Add a Client’ without specifying the name and this should not be allowed by the system as it is a mandatory field.
The test case that we posted yesterday has been further enhanced.
Custom Validation Rules and Web Tests!
Validation Rules: Validation rules are useful when you want to verify that expected data, such as http tag, attribute, request time and text, appear in the responses or perform Web functional testing. Steps to add a custom validation rule in a web test
1 using System;
2 using System.Collections;
3 using System.ComponentModel;
4 using Microsoft.VisualStudio.TestTools.WebTesting;
5 using System.Data;
6
7 public class ControlValidator : ValidationRule
8 {
9 private string _name;
10 public string ControlID
11 {
12 get
13 {
14 return _name;
15 }
16 set
17 {
18 _name = value;
19 }
20 }
21
22 public override string RuleName
23 {
24 get
25 {
26 return "Validate Form Control";
27 }
28 }
29
30 // Specify a description for use in the user interface.
31 // The user sees this description in the Add Validation dialog box.
32 //---------------------------------------------------------------------
33 public override string RuleDescription
34 {
35 get
36 {
37 return "Validates the specified control has some value in it.";
38 }
39 }
40
41 public override void Validate(object sender, Microsoft.VisualStudio.TestTools.WebTesting.ValidationEventArgs e)
42 {
43 FormPostHttpBody requestBody = ((FormPostHttpBody)(e.Request.Body));
44
45 // Add the parameters that we have on the current page
46 foreach (FormPostParameter param in requestBody.FormPostParameters)
47 {
48 // Find the required control from the Html content posted
49 // And check if it has some value
50 if (param.Name == _name)
51 {
52 e.IsValid = !((param.Value == string.Empty));
53 }
54 }
55 }
56 }
Step 1 - Add a Custom validation Rule
Step 2 : Your custom Validation Rule will be visible here
Step 3 : Associate a control with your Validation Rule Finally we wanted to check and add a client without specifying its name. So we are going to do that now by not specifying the name in the web test.
We will copy the Name of the control that has to be validated here. We will require this while checking for the value it has got later on.
We will paste this copied item(name of the control), while adding a validation rule for it. Step 4 : Run the test and View the results After running the web test, the results came out as expected - Add client failed without name being specified.
After adding the name in the web test for a client, it was successfully added in the system and the test passed as predicted. |
|
|||
|
|