Wednesday, June 27, 2012

Web test plugin to encode to base64


This is a Web Performance test plugin that get's the values from 2 context parameters and encrypts them in base64, before running the call:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.VisualStudio.TestTools.WebTesting;


namespace Base64
{
    public class Encrypt64 : WebTestPlugin
    {
        [System.ComponentModel.DisplayName("Context Parameter Name")]
        [System.ComponentModel.Description("Name of the webtest context parameter")]
        public string ContextParameterName
        {
            get;
            set;
        }


        // encode to Base64 function
        static public string EncodeTo64(string toEncode)
        {
            byte[] toEncodeAsBytes = System.Text.ASCIIEncoding.ASCII.GetBytes(toEncode);
            string returnValue = System.Convert.ToBase64String(toEncodeAsBytes);
            return returnValue;
        }


        // decode from Base64 function
        static public string DecodeFrom64(string encodedData)
        {
            byte[] encodedDataAsBytes = System.Convert.FromBase64String(encodedData);
            string returnValue = System.Text.ASCIIEncoding.ASCII.GetString(encodedDataAsBytes);
            return returnValue;
        }


        // this will be executed before the call
        public override void PreWebTest(object sender, PreWebTestEventArgs e)
        {            
            string decode64;
            decode64 = EncodeTo64(e.WebTest.Context["email"] + ":" + e.WebTest.Context["pass"]);
            e.WebTest.Context["GetBase64"] = decode64;
        }


        // this will be executed after the call
        public override void PostWebTest(object sender, PostWebTestEventArgs e)
        {
        }
    }
}

Tuesday, June 26, 2012

Custom Web Performance Rules


Create a Custom Extraction Rule for a Web Performance Test
http://msdn.microsoft.com/en-us/library/ms243179.aspx

Create a Custom Validation Rule for a Web Performance Test
http://msdn.microsoft.com/en-us/library/ms182556

Create a Web Performance Test Plug-In
http://msdn.microsoft.com/en-us/library/ms243191.aspx

Custom Extraction Rule - Extract Cookie Value
http://social.msdn.microsoft.com/Forums/en-US/vstswebtest/thread/cf2bf144-4e87-414f-8aa3-7731f9bc7b73/

Encode/Decode to Base64


//Encode

static public string EncodeTo64(string toEncode)
    {
      byte[] toEncodeAsBytes
            = System.Text.ASCIIEncoding.ASCII.GetBytes(toEncode);
      string returnValue
            = System.Convert.ToBase64String(toEncodeAsBytes);
      return returnValue;
    }


//Decode

    static public string DecodeFrom64(string encodedData)
    {
      byte[] encodedDataAsBytes
          = System.Convert.FromBase64String(encodedData);
      string returnValue =
         System.Text.ASCIIEncoding.ASCII.GetString(encodedDataAsBytes);
      return returnValue;
    }


//Usage

      string myData = “Here is a string to encode.”;

      string myDataEncoded = EncodeTo64(myData);
      Console.WriteLine(myDataEncoded);

      string myDataUnencoded = DecodeFrom64(myDataEncoded);
      Console.WriteLine(myDataUnencoded);

      Console.ReadLine();

Link where I got this from:
http://arcanecode.com/2007/03/21/encoding-strings-to-base64-in-c/

401 - Unauthorized error in Web Performance test

Scenario:
1. In a Visual Studio Web Performance test, make call to a web service that requires credentials.
=> you will get 401 - Unauthorized error (if you did not specify credentials)

Solution:
1. Add a Header (for Basic authentication) to the web test request: Right-click on the call -> Add Header.

2. Add the following info:
Name: "Authorization"
Value: “Basic ” + encodeBase64 (“username:password”)

Use http://www.base64encode.org/ to encode username and password in the following format: "username:password".

It should look like this:

Tuesday, June 19, 2012

RESTClient - usefull tool when working with REST services

You can download the tool from here:
https://addons.mozilla.org/en-US/firefox/addon/restclient/

After installting the Firefox addon you can use it to create all kinds of calls to the REST service.


Monday, June 18, 2012

Nice things you can do with Excel

Excel can be a very useful tool with few tricks.
Here is a collection of some of them:

1. ALT + Enter - to go on second line inside a cell.

2. View -> Freeze Panes -> Freeze top Row.
















3. =IF(logical_test,[value_if_true],[value_if_false]) - to display a result if the logical_test is true or false.

4. =SUMIF(range,criteria,[sum_range]) - to add elements in a range that match given criteria.

5. =COUNTIF(range,criteria) - to count elements in a range that match given criteria.


6. =COUNT(value1,[value2],...) - to count the number of cells in a range that contain numbers.


7. =COUNTBLANK(range) - to count number of blank cells in a range.

8. =COUNTA(value1,[value2],...) - to count the number of cells in a range that are not empty.

9. =OR(logical1,[logical2],...) - logic OR. Same for AND and NOT.

10. =SUM(number1,[number2],..) - to add numbers

11. =CONCATENATE(text1,[text2],...) - to concatenate strings

12. =VALUE(text) - to convert text to numbers

13. =TRIM(text) - to remove all spaces from a string

14. =ROUND(number,num_digits) - to round a number with specified number of digits.

15. =INT(number) - to round a number to the closest integer.

16. =RANDBETWEEN(top,bottom) - generates random number in given range.

17. =ISBLANK(value) - returns True if blank and False otherwise.

18. =CONVERT(number,from_unit,to_unit) - used to convert from a unit to another.

19. Home -> Conditional Formating.























Have fun :)