VB script to send mail automatically from Outlook Mailbox

We have instances where we will be sending template mails repeatedly from our Outlook mail box and drafting them every time is a time consuming process. So to make this easy we can use the below VB script to send those mails automatically just at a click.


String extraction between strings using VB Script MID & Split Commands.

Below is script and explanation for extracting string between string (delimiters) using VB script.

Explained

  • Our objective is to extract as https download link between the delimiters "   <" & ">" from a text file.
  • First we will locate the line in text file "DownloadLink.txt", where the extraction should happen using the search key word "<https".
  • Then comes the extraction part using MID & Split commands. 
  • Split command splits the line wherever it find the ">" delimiter and makes the split elements into an array and the first element (0) (as mentioned in the command) of the array is returned to MID command.
  • Now the MID has the full element starting from "   <https. But all we need is only the link. As mentioned in the command it will return the string starting from the 4th character in the element.
  • Thus we get only our required download link.
VB Script:



Input & Output:








How to find the Outlook profile to use it in Loadrunner MAPI protocol?

Loadrunner MAPI protocol allows us to work with our Outlook mail box. MAPI protocol needs our Outlook profile name to access our mail box.

You can find your Outlook profile name in

Goto Control Panel --> Search mail and click Mail (32-bit) --> Click Show Profiles under Profiles


and you can find the profile name. In the screenshot profile name is "Outlook".


You can see that above profile name is used in the MAPI Logon function below.



How to execute VB script in Loadrunner Http/Html Protocol?

VB scripts cannot be executed directly from vugen. So what we will be doing is, we will be launching the vb script from a batch file and that batch file will be called from the loadrunner.
Its like executing the vb script from command line.

Step 1: Creating a Batch file

Open a notepad and paste the below command to call the vb script and save the notepad as .bat (batch) file.


Step 2: Creating a Loadrunner Web Script

Below is the loadrunner script to execute the batch file.



C program to convert hexadecimal value to its equivalent text value to be used in Loadrunner.

For example

Hexadecimal value passed in the url: %74%65%78%74%20%76%69%6E%6F%74%68%2E%74%78%74

Text value: text vinoth.txt

Below is the C program which does the above conversion ( Hex to Plain Text conversion)



Output:




C program to convert a text into its equivalent hexadecimal value to be used in Loadrunner

Loadrunner has a built in function called web_convert_param function which converts HTML to a URL or plain text or the vice-versa.
But in my case, I had a file upload script in which the text files names that are uploaded are converted into its equivalent hexadecimal value and they were passed in the request url.
Since they were passed in the url the hexadecimal values were also appended with %.

For example

Text File uploaded : text vinoth.txt

hexadecimal value passed in the url: 74%65%78%74%20%76%69%6E%6F%74%68%2E%74%78%74%

Below is the C program which does the above conversion (Plain Text to Hex conversion)

Output:


VB Script to fetch the names of sub folders in a folder and write it to a text file

Say for example we have different file upload scenarios and we have kept the files in different folder accordingly and we have to input the file path along with the file name. Doing this manually is tedious. 

So the below VB script simplifies the work, all it does is it reads the sub folder names under the parent folder that we input and writes it to the output by concatenating the both.

VB Script:

If at all you want only the subfolder name to be written to the Output file then

comment out  --- logFile.writeline FilePath
&
remove the comment from --- logFile.writeline(objSubFolder.name)

VB script to fetch the file names and write it to a text file

We all have come across a loadrunner script in which file upload will happen and we would have parameterized the file path & file name. Consider if we have 1000's of files and we need to give them as parameter input. So entering the file path and file name manually into the file parameter would be a time consuming process.

Below VB script simplifies the above process by just a click. All we have to do is to input the file path where inputs files are placed and mention the output file to write the the same.

VB Script:

If at all you want only the file name to be written to the Output file then

comment out  --- logFile.writeline FilePath
&
remove the comment from --- logFile.writeline(file.name)

How to add IF ELSE block in Truclient Protocol Loadrunner?

Steps to add IF ELSE Condition Block in Truclient Protocol

1. Right Click the step which has to be validated and Select If Clause --> Group Into.

2. Now the selected step comes under the IF condition
3. Click the Add Else Link and drag and drop the step to executed in the Else Condition.



4. Now add a condition in the IF blocks JavaScript to validate and execute the steps.


How to resolve Drag and Scroll not working issue in TruClient Protocol Loadrunner

I was doing truclient protocol based scripting for one of the applications developed on WebSwings. So the entire webpage was considered as one single element or object and all the clicks made on that page were being recorded using their X & Y coordinates.

Issue:

  • So when I click and drag the page slider down in the scroll bar it was getting recorded as a 'Drag' step.
  • But during replay script was not able to perform the drag since it was not able to identify the object.


Solution:

  • Instead of doing a click and drag of the page slider, scroll the page by clicking on the down button in the scroll bar. 

  • It will get recorded as 'Click' step.
  • Now change the step Action from 'Click' to 'Mouse Down'. 


  • Increase the Step Minimum Time to 10 sec. This needs to be done because we need to give sometime for the page to scroll before the next step gets executed. Since Truclient is asynchronous in nature.



Similarly for drag or scroll up click the up button in the scroll bar and change the step action to 'Mouse Up'.

Thats it now your page drag will work without any issues.

Why & How to do browser Resizing in TruClient Protocol Loadrunner

Need for browser Resizing:

I was doing truclient protocol based scripting for one of the applications developed on WebSwings. So the entire webpage was considered as one single element or object and all the clicks made on that page were being recorded using their X & Y coordinates.

The issue was that browser size varied between Developer and Load modes and identifying the objects using X & Y coordinates failed.

The solution is to make the browser size same in both the modes for which Browser Resize step comes handy.

How to do browser Resizing:

In Development mode, before recording we need to add the first step as Browser Resize and set the browser to our desired size.

Step 1: Goto Toolbox --> Functions --> Generic Browser Action and by default it will be Navigate step.


Step 2: Expand the Navigate step Goto Step --> Action and change the Action from Navigate to Resize.





Step 3: Now click on the Width or on the Height and set the Width and Height to the desired px value. In my case I have set Width to 800px and Height to 600px.





Step 4:  Now record all your flow steps after the Resize step.

Thats it, now when you run the script in Development mode first the browser will be set to the desired Width & Height and then the steps will be executed.

Now lets see how to set the Browser width and Height in Load mode.

Step 1: Disable the Resize step in Development mode and save it.

Step 2: Goto RunTimeSettings --> Others --> Non Interactive Window Size.

Step 3: Check both the options and set the Width to 800px and Height to 600px and save the script.



Thats it. Now browser will be set to the desired size in load mode as well.

Since we have done Browser Resizing identifying the objects using X & Y coordinates will no more fail.

How to clear the text field in Type Step TruClient Protocol Loadrunner.

If at all a text field in a web page is having sample values and when we are trying to type in some text in the filed using Type Step in Truclient, we need to clear the sample input first and then enter only our actual text input. Otherwise our actual text input will get appended to the existing sample input. Thus entering a wrong input value.

Follow the below steps to over come this.

1. Expand the Type Step.
2. Goto Arguments.
3. Set the Clear Argument value to True. This will clear the existing vales in the text filed and enter our script input.



Note - The default value for the Clear Argument is True.

Steps to view run time replay in load mode - TruClient Protocol - Loadrunner

In the Load mode of Truclient Protocol we will not be able to see the replay snapshots. So if at all we need to check if the flow is working properly in load mode, then we can enable the run time replay using the below steps.

1. Create the script in Development or Interactive mode, save it and close the Truclient browser.
2. Open the script folder.
3. Open 'default.cfg' file in notepad.
4. Search for 'PaintWindowsInLoad' and change its value from 0 to 1.
5. Save the 'default.cfg' file.
6. Now replay the script in load mode and you can see the Truclient browser launching and steps getting replayed.


How to find the RAM memory footprint of TruClient Vusers?


  • TruClient is a GUI based Loadrunner protocol. 
  • One of the major setbacks of this protocol is its 1 vusers consumes a lot of physical RAM memory. Thus limiting the Vuser allocation to Load Generators.


In this post we will discuss about How to find the RAM memory footprint of TruClient Vusers?


  • First create a TruClient Script for your desired flow.
  • Then add the script to controller and assign 10 Vusers to it and start the run
  • Go to --> Task Manager --> Performance Tab --> Open Resource Monitor --> Memory Tab. Here you can see the list process that are running and their memory usage.
  • TruClient Vusers use browsers to execute the script and you can find a bunch of browser exe processes opened up. In our case it is firefox.exe.
  • Check the working set column which shows RAM memory usage for each exe process i.e each Vuser. In our case each Vusers needs around 200 MB of memory.
  • Based on this you can calculate the amount of RAM needed for other OS based activities and the amount of RAM needed for our execution and distribute the Vusers accordingly.



Why & How to use Wait for Object in TruClient Protocol - Loadrunner

Why to use Wait for Object?

I would suggest using Wait for Object function over normal Wait. TruClient protocol is asynchronous in nature which means that steps do not depend on each other during execution. In this case if we use a normal Wait function defined in seconds and if the step takes more time to complete than the time defined in the Wait function then the next step will fail since it will be unable to find the object.
To overcome this we must use Wait for Object function which will wait till a particular object loads in the page and this avoids the failing of subsequent steps.

How to use Wait for Object?

Step 1: Goto Toolbox --> Functions --> Wait for Object and place it below the desired step.


Step 2: Click Click to Choose and Object and select an object from the page. Following which the Highlighted Object details popup open showing the object match in Green.




Step 3: Goto Step --> End Event and change the end event from Automatic: Action Completed to Object Exists


Step 4: Click the search icon and select the same object chosen in Step 2. Following which Highlighted Object details popup open showing the object match in Green similar to that of Step 2.



Thats it !! Your Wait for Object Step is completed.




C Program to write loadrunner parameter output to text file


  • Assign the file name & location to the variable filename.
  • fopen() function is used to open the file.
  • a+ – Opens a file in read and write mode and sets pointer to the first character in the file. And, it can’t modify existing contents.
  • Use lr_eval_string() function to read the correlation parameter value.
  • fprintf() function is used to write into the file. 
  • fclose() function is used to close the file.

C Program:









Transaction validation in loadrunner using web_reg_find function

  • We can use the SaveCount attribute of web_reg_find function to validate the transactions.
  • SaveCount attribute of web_reg_find function saves the number of matches (count) found for the given text in a parameter.
  • We need to use this Count value in the IF block to validate the transaction.
  • If the Count value is greater than 0 we will pass the transaction else we will fail it.
Code Snippet:


Transaction validation in loadrunner using web_reg_save_param function


  • We can use the count of web_reg_save_param function to validate the transactions.
  • Set the ORDINAL value of web_reg_save_param function to ALL.
  • This will generate a parameter CorrelationParameter_Count to fetch the total matches found for our defined Left and Right boundaries.
  • We need to use this CorrelationParameter_Count value in the IF block to validate the transaction.
  • If  CorrelationParameter_Count value is less than 1 we will fail the transaction else we will pass it.
Code Snippet:


C Program to generate Randum numbers in loadrunner using srand() & rand()

Program 1 - Using Loadrunner Parameter

C Code:














Output:








Program 2 - Without Using Loadrunner Parameter


C Code:









Output:



Alternative steps in Loadrunner TruClient Protocol

  • Alternative steps helps you to choose different ways to perform the same action in a step. 
  • For example, in a drop-down list, Ajax TruClient gives you the option of specifying your selection by name or by the number in which it appears in the list.
  • Sometimes the recorded step selection method might not work. You can modify such steps to perform the given action using the alternate step selection. 
  • Steps that have alternative options are labeled with an alternative step symbol highlighted in the below image. Click it to view the alternative options for that step. Click the desired alternative and select Back.



  • Above is the snapshot of a step in which Customer ID "BM1005" was searched and selected.
  • The alternative steps feature gives you the four different options of defining of selecting the Customer ID "BM1005".
  • You can click on the play button (highlighted in the below image) on the right side to check how each step will behave, before finalizing on the correct step.
  • These alternate steps are something similar to ordinal value in web HTTP protocol.


Parameterization in TruClient Protocol Loadrunner - JavaScript Based (Method 2 - LR.getParam)


Step 1: Create a parameter under Parameters Dialog Box (Highlighted in RED). I have created a File Parameter of name “Username”


Step 2 : Click the Develop Script button

Step 3 : Fetch the parameters from “Username” using LR.getParam function (i.e.) replace the value to be parameterized with the following code LR.getParam(“Username”) in Value filed under Arguments section. (Code Highlighted in RED)



Step 4 : By default Value  field will be in Plain Text. Now click on the drop down arrow and select JavaScript <JS>. (Highlighted in GREEN)