Dmitry Motevich - CV/Resume

My CV/Resume.
In English

Мое резюме.
На русском языке

LoadRunner - how to convert a plain text to URL format

The task - How to convert a plain text string to URL-format in LoadRunner?

Several days ago I faced with a simple task - it was needed to convert a passed parameter (which was in a plain text form) to URL-format. In other words, I had to convert:
  • string "ab" to the same string "ab"
  • string "a b" to the string "a%20b"
  • string "a b_c%" to "a%20b%5Fc%25"
  • and so on ...

The cause - Why it was needed?

LoadRunner script contained parameters, which should be passed to URL directly. Some my parameters contained special characters like spaces (" "), quotes ("), percentage ("%"), asterisks ("*") and others. To be processed correctly by a browser and a web server, these characters should be translated and passed as their hex-codes.

For example:
  • a space character (" ") has hex-code 0x20, so it should be passed as "%20"
  • underline character (" ") has hex-code 0x5F, so it should be passed as "%5F"

The ways on how to perform the task.

To perform this task I decided to use LoadRunner's web_convert_param function. I didn't know at that time that this function does not satisfy my requirements. So, I was reluctant to write my own function EncodePlainToURL. Well, let's see both solutions.

  1. web_convert_param function.

    As Help says, web_convert_param function converts HTML to a URL or plain text.
    So, I wrote this code:
    char sIn[] = "t es%d$ + eprst_";

    lr_save_string(sIn, "InputParam");
    web_convert_param("InputParam", "SourceEncoding=PLAIN",
    "TargetEncoding=URL", LAST);

    lr_output_message("%s", lr_eval_string("{InputParam}"));
    Press F5 to execute the code, and.... H'm....
    The input string "t es%d$ + eprst_" was converted to "t+es%25d%24+%2B+eprst_".
    That means that space (" ") was converted to a plus ("+"). I expected to see "%20" instead of a plus character.

    Actually, it seems that "+" and "%20" are twins. For example Google uses a plus to encode a space within a search query. For example, if the query is "some text", then the URL will be:

    I was tried to encode spaces (and others special characters) to their hex-codes.
    That's why the following function was written:

  2. EncodePlainToURL function.

    The logic is simple enough:
    • If the current character is a digits or an alphabetic letter, then pass it "as is"
    • Otherwise the current character is a special one. So, hex-code should be written in this case

    This is a code of EncodePlainToURL function:
     * EncodePlainToURL converts a plain text string to an URL-form string.
     * Parameters: sIn - input string to be encoded to URL format
     * sOut - output buffer
     * Note: the size of "sOut" parameter should be at least equal to triple size
     * of "sIn" parameter plus one character(for end-terminator '\0')
     * Author: Dmitry Motevich
     * Examples: "a" -> "a"
     * "a b" -> "a%20b"
     * "a b_cc:\/c%" -> "a%20b%5Fcc%3A%2Fc%25"

    char *EncodePlainToURL(const char *sIn, char *sOut)

        int i;
        char cCurChar;
        char sCurStr[4] = {0};

        sOut[0] = '\0';

        for (i = 0; cCurChar = sIn[i]; i++)

            // if this is a digit or an alphabetic letter
            if (isdigit(cCurChar) || isalpha(cCurChar))

                // then write the current character "as is"
                sprintf(sCurStr, "%c", cCurChar);

                // else convert it to hex-form. "_" -> "%5F"
                sprintf(sCurStr, "%%%X", cCurChar);

            // append current item to the output string
            strcat(sOut, sCurStr);

        return sOut;

    The example of usage is:
    char sIn[] = "t es%d$ + eprst_";
    char sOut[100];

    lr_output_message("%s", EncodePlainToURL(sIn, sOut));
    Execute the code, and see the result:
    The input string "t es%d$ + eprst_" was converted to "t%20es%25d%24%20%2B%20eprst%5F".

    Yeah! :)
    All special characters (including spaces) were converted to hex-code, i.e. to URL-format!

Dmitry Motevich

QTP - How to get font size/color, background color and other attributes of controls

Today I faced with the following task with QTP (QuickTest Professional) - how to get some attributes (such as: font size, font color, background color and so on) for any control on a web page?

Piece of cake! :)
Let's see ways how it can be done.

The task: get font size, font color, background color and others possible parameters from the start page:

The solution:
  1. First of all, I tried to use GetROProperty method.
    I selected "Welcome to Gmail" label with QTP object spy and added them to Object Repository:
    Well, now I know the class of web control - WebElement.

    Then, I open QuickTest Professional Help, search for "WebElement Identification Properties" and see that there are not needed properties (font name, font color, size, ...).

    Help reading shown that it is possible to get needed properties for some objects, for example, for Link. Please, see "Link Identification Properties" from the QTP Help:

    Property Name: Description
    • background color: The link's background color.
    • color: The link's color.
    • font : The link's font.

    So, these properties work correctly for Link. For example, the following code:
    Browser("Welcome to Gmail").Page("Welcome to Gmail").Link("About Gmail").GetROProperty("color")
    returns value #0000ff for "About Gmail" link:
    In terms of RGB (red-green-blue), the value #0000ff means that blue-color is enabled.
    It looks like truth :)

    This approach (GetROProperty method) has a limitation - it can be applied for some objects. In my case (I use WebElement object) this methods cannot be applied.

    Thanks to Mr. Google :) It found an appropriate solution:
  2. currentStyle object!
    The main idea is to read:
    For example, use:
    • color property to get the color of the text
    • backgroundColor property to get the backgroung color (behind the content of the object)
    • fontSize property to get the font size
    • fontStyle property to get the font style
    • fontFamily property to get the font family
    • fontWeight property to get the font weight
    • and so on

    Please, read more detailed info on properties of currentStyle object:

    So, I used this code in my QTP script:

    Dim ctrlWebEl, objWebEl

    Set ctrlWebEl = Browser("Welcome to Gmail").Page("Welcome to Gmail").WebElement("Welcome to Gmail")

    Set objWebEl = ctrlWebEl.Object

    sColor = objWebEl.currentStyle.color

    sBackgrColor = objWebEl.currentStyle.backgroundColor

    sFontSize = objWebEl.currentStyle.fontSize
    sFontStyle = objWebEl.currentStyle.fontStyle

    sFontFamily = objWebEl.currentStyle.fontFamily
    sFontWeight = objWebEl.currentStyle.fontWeight

  3. Result is:
    The last thing I have to do is to get a numerical value of background color.
    For that I recorded another object - WebElement("corner_tl"):
    Note: when recording, click at the right of "Welcome to Gmail" text.

    I executed my QTP script for that WebElement and got results:

    Background color is #c3d9ff

    Now, I think, mission is completed :)
    All attributes (font size/color/weight, backgroung color) are gathered.

Summary: The simple way to get different attributes of controls from QTP is a usage of currentStyle object .
    Enjoy QuickTest Professional :)

    Dmitry Motevich

Related articles: