Showing posts with label QA. Show all posts
Showing posts with label QA. Show all posts

Tuesday, August 22, 2023

PowerShell to write XML with attributes on new line

Context

Many times after patch deployment of the application into the server there will be questions on what changed? The source code is obviously changed and the binaries can't be compared to find out what changed.

But the textual configuration files can easily be compared. Take a backup of existing files. Do the patching and compare what changed.

This post is assuming the deployment tools are using PowerShell to change the config files.

Problem

Look at the image below.

It shows there are a lot of changes done to the file. But really there is only one change. dbserver3->dbserver2

As we can easily understand the comparison considered the files as text, not as XML, and found a lot of differences.

Approaches

If the number of files is less this is fine but that is not the case in enterprise. There are multiple approaches to this problem.

A tool that understands XML and compares

The above comparison tool is not recognizing the XML format instead it compared textually. Find another tool that understands the XML format and compare accordingly.

To date, we didn't find any such tool. Please comment if there are tools that are free and export the comparison report.

Always have attributes on a new line

In this approach make sure all the tools and programs that modify the XML write attributes on a new line.
Since PowerShell is running on top of .Net it is easy to get anything working in PowerShell that works in .Net. Google easily lands us in pages that say use the XMLWriterSettings.NewLineOnAttributes to get the job done. Unfortunately, it is not working out of the box.

But when we combine the .Indent property with .NewLineOnAttributes, it works fine.

[XML]$doc = get-content ".\input.xml"
$xwSettings = new-object System.Xml.XmlWriterSettings
$xwSettings.Indent = $true
$xwSettings.NewLineOnAttributes = $true
$xmlWriter = [Xml.XmlWriter]::Create("output.xml", $xwSettings)
$doc.Save($xmlWriter)
$xmlWriter.Dispose()

The above code works. Now the question is, is this documented? Oh yes in the remarks section.
Of course, the default value of the Indent property is false. The comparison looks as below after using the above code.


Happy formatting.

Tuesday, July 16, 2013

Recording VSTS webtest of windows application which uses https web services

Whenever we develop a web site or web application, it is mandatory that we should do load testing before production. It will give us an idea about how many users and requests it can handle per second in a given server environment. In theory its easy to say we should do the load testing. But in practice, very less people knows, how it is being worked out and what are the software tools used to do load testing.

One of the load testing tool is Visual Studio itself ! But before going into load testing in Visual studio, let us see what a load testing software in general should provide and how a load testing is carried out.

Features of load testing software

  • Recording
    • Ability to record the different use cases of the application. Mainly uses script for storing purpose.
    • Ability to add parameters / tokens into the recorded use cases / script for handling virtual users and passing other runtime values.
  • Play back
    • Ability to run the recorded use cases / scripts by replacing the tokens with run time values
    • Ability to run simultaneously from multiple machines or agents.
    • Controller agent model to collect data from the nodes which are executing the scripts.
    • Ability to create virtual users in the controller agent environment.

Steps to do load testing

  1. Record the use cases in a format which can be playable
  2. Adding parameters (optional)
    1. Add tokens or place holders to the recorded script so that it can be replaced by actual values at run time
    2. Write the token / parameter replacement logic.
  3. Define web load test cases. eg: 25 virtual users
  4. Setup the agents.
  5. Run the recorded load test cases and collect the results.

Web performance load testing using Visual Studio

This feature is available in high end versions (Ultimate) of Visual Studio. If your Visual Studio supports load testing, you can see the webtest template and load test template. If your application is a web site its very easy to record the scripts. This is because the Visual Studio has an in built mechanism to record the http(s) traffic from internet explorer. If your internet explorer is in record mode, you can easily perform use cases and record the action. But if you are developing a windows application which uses http(s), it is little difficult to record because Visual Studio cannot intercept your windows desktop application to capture the http(s) traffic. So what to do? In fact that is the aim of this post.

Recording visual studio web test in desktop world

There is a really really useful tool called fiddler. It must be familiar to the web developers but not for windows developers. This tool can act as proxy which sits between any application and the network to capture all the http(s) requests and responses. Now a days most of its duties can be done by the F12 browser tools. But in the desktop environment, fiddler still has importance. Below is the sequence to create web test of windows applications using fiddler.
  1. Run Fiddler
    1. Setup support for https if required
  2. Run the application
  3. Execute a use case
  4. Goto fiddler and select File -> Export Sessions -> All Sessions
  5. Select Visual Studio WebTest
  6. Add the exported web test to Visual Studio project.
  7. Add tokens / parameters to the web test.
  8. Clear the fiddler session
  9. Repeat the steps 3-8 for all the use cases in your application which you want to load test.