Wednesday, December 21, 2016

Web Performance Testing with Visual Studio - Extracting login token

Introduction

Visual Studio Enterprise 2015 or Visual Studio Ultimate 2013, gives you the possibility to test the performance of your application. In this article we'll show you how to extract .json login token for later use by using a Text Extraction Rule. If you don't have this information, after login, you'll get a 401 Unauthorized error.

Extract token

First of all, run your recorded test and check the test result. Go to the request that contains the token and check Response tab. In the example below, you can notice that the access token is stored in a .json.




Using extraction rule

Extracting the token is possible, by using Extraction Rules functionality. To do this, go to your recorded request (for login), right click on request name and add new extraction rule.



Select the extraction rule of type Extract Text, enter Context Parameter Name (the name of a test variable to associate with the extracted value), Starts With and Ends With, like in the image below.



After doing this, your request should look like this.



Use token to authorize

The extracted token should be used in the requests performed after login. To do this select the request, right click and Add Header



In properties, add an Authorization header with this value: Bearer {{myToken}}.



Happy testing and... make it green, becomes a dream :)


Monday, December 5, 2016

Web Performance Testing with Visual Studio - Add a CSV File Data Source

Introduction

Visual Studio Enterprise 2015 or Visual Studio Ultimate 2013, gives you the possibility to test the performance of your application. In this article we'll show you how to use a CSV Data Source in order to bind data from you post parameters o string body to CSV values. It is required that you already know how to create a new performance test/record it, etc. If you don't, you can inspect MSDN documentation here.
Why should I use CSV Data Source?

You can use data binding in a Web performance test to provide values for input form posts or string body. For example we may have a list of logon emails and passwords that would be used during the execution of web performance tests to try repeated logons. Or, we can create a data source for the parts of the tests that are using the same input values. If those values will be changed, we only have to update the CSV file.

How to add CSV Data Source?

This link explains how to bind your data to a CSV file: https://msdn.microsoft.com/en-us/library/bb385971(v=vs.90).aspx.

"To add the data source to the Web test
  1. In the Web Test Editor, right-click the top node of the Web test and then click Add Data Source.
    The New Test Data Source Wizard appears.
  2. In the Data source name box type a name for your data source.
  3. In the Data source type list click CSV File.
  4. Click Next.
  5. In the Choose a CSV file box enter the path and name of the file, or click the ellipsis to browse to the file. For example, enter the following:
    <Your Path>\FileName.csv
    The data from the CSV file appears in the Preview data pane. The first 1,000 rows of data are displayed.
  6. Click Finish.
    A dialog box appears that asks you if you want to add the file to your current project. You can use the following information to help you decide:
    Response
    Result
    Advantage
    Yes
    The file is copied to the project.
    When the project is deployed, there is no extra work that is required.
    No
    The file is not copied to the project. When the project is deployed, you might have to update the path of the file.
    Some data files can be very large, and should be maintained separate from the project. Some data files must be shared among several members of a team, and should be maintained in a central location that all members can access.
  7. Click Yes or No.
    Data Sources node will be added to the Web test, and the text file will appear as a table in the hierarchy.
  8. On the File menu click Save to save the Web test."

The CSV file should have this format:
- the first record represents the columns to be bind to
- the following records represents the data you want to bind

How to bind Data Source in your tests?

You can replace input posts with data from your Data Source previously added.



You can also replace data inside string body with CSV values by replacing recorded value with format:
"{{DataSourceName.CSVFileName#csv.ColumnName}}"
Here is an example for a string body where title value was replaced with a value from a CSV file:




Happy testing and... make it green, becomes a dream :)

Popular Posts